AppDelegate.m 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. Licensed to the Apache Software Foundation (ASF) under one
  3. or more contributor license agreements. See the NOTICE file
  4. distributed with this work for additional information
  5. regarding copyright ownership. The ASF licenses this file
  6. to you under the Apache License, Version 2.0 (the
  7. "License"); you may not use this file except in compliance
  8. with the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing,
  11. software distributed under the License is distributed on an
  12. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  13. KIND, either express or implied. See the License for the
  14. specific language governing permissions and limitations
  15. under the License.
  16. */
  17. //
  18. // AppDelegate.m
  19. // ionic-tabs
  20. //
  21. // Created by ___FULLUSERNAME___ on ___DATE___.
  22. // Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
  23. //
  24. #import "AppDelegate.h"
  25. #import "MainViewController.h"
  26. #import <Cordova/CDVPlugin.h>
  27. @implementation AppDelegate
  28. @synthesize window, viewController;
  29. - (id)init
  30. {
  31. /** If you need to do any extra app-specific initialization, you can do it here
  32. * -jm
  33. **/
  34. NSHTTPCookieStorage* cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
  35. [cookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
  36. int cacheSizeMemory = 8 * 1024 * 1024; // 8MB
  37. int cacheSizeDisk = 32 * 1024 * 1024; // 32MB
  38. #if __has_feature(objc_arc)
  39. NSURLCache* sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:cacheSizeMemory diskCapacity:cacheSizeDisk diskPath:@"nsurlcache"];
  40. #else
  41. NSURLCache* sharedCache = [[[NSURLCache alloc] initWithMemoryCapacity:cacheSizeMemory diskCapacity:cacheSizeDisk diskPath:@"nsurlcache"] autorelease];
  42. #endif
  43. [NSURLCache setSharedURLCache:sharedCache];
  44. self = [super init];
  45. return self;
  46. }
  47. #pragma mark UIApplicationDelegate implementation
  48. /**
  49. * This is main kick off after the app inits, the views and Settings are setup here. (preferred - iOS4 and up)
  50. */
  51. - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
  52. {
  53. CGRect screenBounds = [[UIScreen mainScreen] bounds];
  54. #if __has_feature(objc_arc)
  55. self.window = [[UIWindow alloc] initWithFrame:screenBounds];
  56. #else
  57. self.window = [[[UIWindow alloc] initWithFrame:screenBounds] autorelease];
  58. #endif
  59. self.window.autoresizesSubviews = YES;
  60. #if __has_feature(objc_arc)
  61. self.viewController = [[MainViewController alloc] init];
  62. #else
  63. self.viewController = [[[MainViewController alloc] init] autorelease];
  64. #endif
  65. // Set your app's start page by setting the <content src='foo.html' /> tag in config.xml.
  66. // If necessary, uncomment the line below to override it.
  67. // self.viewController.startPage = @"index.html";
  68. // NOTE: To customize the view's frame size (which defaults to full screen), override
  69. // [self.viewController viewWillAppear:] in your view controller.
  70. self.window.rootViewController = self.viewController;
  71. [self.window makeKeyAndVisible];
  72. return YES;
  73. }
  74. // this happens while we are running ( in the background, or from within our own app )
  75. // only valid if ionic-tabs-Info.plist specifies a protocol to handle
  76. - (BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation
  77. {
  78. if (!url) {
  79. return NO;
  80. }
  81. // all plugins will get the notification, and their handlers will be called
  82. [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]];
  83. return YES;
  84. }
  85. // repost all remote and local notification using the default NSNotificationCenter so multiple plugins may respond
  86. - (void) application:(UIApplication*)application
  87. didReceiveLocalNotification:(UILocalNotification*)notification
  88. {
  89. // re-post ( broadcast )
  90. [[NSNotificationCenter defaultCenter] postNotificationName:CDVLocalNotification object:notification];
  91. }
  92. #ifndef DISABLE_PUSH_NOTIFICATIONS
  93. - (void) application:(UIApplication*)application
  94. didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
  95. {
  96. // re-post ( broadcast )
  97. NSString* token = [[[[deviceToken description]
  98. stringByReplacingOccurrencesOfString:@"<" withString:@""]
  99. stringByReplacingOccurrencesOfString:@">" withString:@""]
  100. stringByReplacingOccurrencesOfString:@" " withString:@""];
  101. [[NSNotificationCenter defaultCenter] postNotificationName:CDVRemoteNotification object:token];
  102. }
  103. - (void) application:(UIApplication*)application
  104. didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
  105. {
  106. // re-post ( broadcast )
  107. [[NSNotificationCenter defaultCenter] postNotificationName:CDVRemoteNotificationError object:error];
  108. }
  109. #endif
  110. #if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000
  111. - (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
  112. #else
  113. - (UIInterfaceOrientationMask)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
  114. #endif
  115. {
  116. // 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).
  117. NSUInteger supportedInterfaceOrientations = (1 << UIInterfaceOrientationPortrait) | (1 << UIInterfaceOrientationLandscapeLeft) | (1 << UIInterfaceOrientationLandscapeRight) | (1 << UIInterfaceOrientationPortraitUpsideDown);
  118. return supportedInterfaceOrientations;
  119. }
  120. - (void)applicationDidReceiveMemoryWarning:(UIApplication*)application
  121. {
  122. [[NSURLCache sharedURLCache] removeAllCachedResponses];
  123. }
  124. @end