Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix openUrl #5

Merged
merged 1 commit into from
Apr 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 54 additions & 56 deletions CordovaLib/Classes/Public/CDVAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,96 +23,94 @@ @implementation CDVAppDelegate

@synthesize window, viewController;

- (id)init
{
/** If you need to do any extra app-specific initialization, you can do it here
* -jm
**/
NSHTTPCookieStorage* cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
-(id) init {
/** If you need to do any extra app-specific initialization, you can do it here
* -jm
**/
NSHTTPCookieStorage* cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];

[cookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
[cookieStorage setCookieAcceptPolicy : NSHTTPCookieAcceptPolicyAlways];

int cacheSizeMemory = 8 * 1024 * 1024; // 8MB
int cacheSizeDisk = 32 * 1024 * 1024; // 32MB
NSURLCache* sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:cacheSizeMemory diskCapacity:cacheSizeDisk diskPath:@"nsurlcache"];
[NSURLCache setSharedURLCache:sharedCache];
int cacheSizeMemory = 8 * 1024 * 1024; // 8MB
int cacheSizeDisk = 32 * 1024 * 1024; // 32MB
NSURLCache* sharedCache = [[NSURLCache alloc] initWithMemoryCapacity : cacheSizeMemory diskCapacity : cacheSizeDisk diskPath : @"nsurlcache"];
[NSURLCache setSharedURLCache : sharedCache];

self = [super init];
return self;
self = [super init];
return self;
}

#pragma mark UIApplicationDelegate implementation

/**
* This is main kick off after the app inits, the views and Settings are setup here. (preferred - iOS4 and up)
*/
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
CGRect screenBounds = [[UIScreen mainScreen] bounds];
-(BOOL) application : (UIApplication*) application didFinishLaunchingWithOptions : (NSDictionary*) launchOptions {
CGRect screenBounds = [[UIScreen mainScreen] bounds];

self.window = [[UIWindow alloc] initWithFrame:screenBounds];
self.window.autoresizesSubviews = YES;
self.window = [[UIWindow alloc] initWithFrame : screenBounds];
self.window.autoresizesSubviews = YES;

// only set if not already set in subclass
if (self.viewController == nil) {
self.viewController = [[CDVViewController alloc] init];
}
// only set if not already set in subclass
if (self.viewController == nil) {
self.viewController = [[CDVViewController alloc] init];
}

// Set your app's start page by setting the <content src='foo.html' /> tag in config.xml.
// If necessary, uncomment the line below to override it.
// self.viewController.startPage = @"index.html";
// Set your app's start page by setting the <content src='foo.html' /> tag in config.xml.
// If necessary, uncomment the line below to override it.
// self.viewController.startPage = @"index.html";

// NOTE: To customize the view's frame size (which defaults to full screen), override
// [self.viewController viewWillAppear:] in your view controller.
// NOTE: To customize the view's frame size (which defaults to full screen), override
// [self.viewController viewWillAppear:] in your view controller.

self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];

return YES;
return YES;
}

// this happens while we are running ( in the background, or from within our own app )
// only valid if 40x-Info.plist specifies a protocol to handle
- (BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation
{
if (!url) {
return NO;
}

NSMutableDictionary * openURLData = [[NSMutableDictionary alloc] init];
-(BOOL) application : (UIApplication *) app openURL : (NSURL *) url options : (NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
if (!url) {
return NO;
}

[openURLData setValue:url forKey:@"url"];
NSMutableDictionary * openURLData = [[NSMutableDictionary alloc] init];

if (sourceApplication) {
[openURLData setValue:sourceApplication forKey:@"sourceApplication"];
}
[openURLData setValue : url forKey : @"url"];

if (annotation) {
[openURLData setValue:annotation forKey:@"annotation"];
}
if (options[UIApplicationOpenURLOptionsSourceApplicationKey]) {
[openURLData setValue : options[UIApplicationOpenURLOptionsSourceApplicationKey] forKey : @"sourceApplication"];
}

// all plugins will get the notification, and their handlers will be called
[[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]];
[[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLWithAppSourceAndAnnotationNotification object:openURLData]];
if (options[UIApplicationOpenURLOptionsAnnotationKey]) {
[openURLData setValue : options[UIApplicationOpenURLOptionsAnnotationKey] forKey : @"annotation"];
}

return YES;
// all plugins will get the notification, and their handlers will be called
[[NSNotificationCenter defaultCenter] postNotification : [NSNotification notificationWithName : CDVPluginHandleOpenURLNotification object : url]];
[[NSNotificationCenter defaultCenter] postNotification : [NSNotification notificationWithName : CDVPluginHandleOpenURLWithAppSourceAndAnnotationNotification object : openURLData]];

return YES;
}

#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000
- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000
-(NSUInteger) application : (UIApplication*) application supportedInterfaceOrientationsForWindow : (UIWindow*) window
#else //CB-12098. Defaults to UIInterfaceOrientationMask for iOS 9+
- (UIInterfaceOrientationMask)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window

- (UIInterfaceOrientationMask) application : (UIApplication*) application supportedInterfaceOrientationsForWindow : (UIWindow*) window
#endif
{
// iPhone doesn't support upside down by default, while the iPad does. Override to allow all orientations always, and let the root view controller decide what's allowed (the supported orientations mask gets intersected).
NSUInteger supportedInterfaceOrientations = (1 << UIInterfaceOrientationPortrait) | (1 << UIInterfaceOrientationLandscapeLeft) | (1 << UIInterfaceOrientationLandscapeRight) | (1 << UIInterfaceOrientationPortraitUpsideDown);
// iPhone doesn't support upside down by default, while the iPad does. Override to allow all orientations always, and let the root view controller decide what's allowed (the supported orientations mask gets intersected).
NSUInteger supportedInterfaceOrientations = (1 << UIInterfaceOrientationPortrait) | (1 << UIInterfaceOrientationLandscapeLeft) | (1 << UIInterfaceOrientationLandscapeRight) | (1 << UIInterfaceOrientationPortraitUpsideDown);

return supportedInterfaceOrientations;
return supportedInterfaceOrientations;
}

- (void)applicationDidReceiveMemoryWarning:(UIApplication*)application
{
[[NSURLCache sharedURLCache] removeAllCachedResponses];
-(void) applicationDidReceiveMemoryWarning : (UIApplication*) application {
[[NSURLCache sharedURLCache] removeAllCachedResponses];
}

@end