Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.11 KB | None | 0 0
  1. #import "PushNotificationManager.h"
  2.  
  3. - (void) onPushAccepted:(PushNotificationManager *)pushManager withNotification:(NSDictionary *)pushNotification {
  4. NSLog(@"Push notification received");
  5. }
  6.  
  7. //
  8. // AppDelegate.m
  9. // RistoranteStockholm
  10. //
  11. // Created by ___FULLUSERNAME___ on ___DATE___.
  12. // Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
  13. //
  14.  
  15. #import "AppDelegate.h"
  16. #import "MainViewController.h"
  17. #import <Cordova/CDVPlugin.h>
  18.  
  19. #import "PushNotificationManager.h"
  20.  
  21. - (void) onPushAccepted:(PushNotificationManager *)pushManager withNotification:(NSDictionary *)pushNotification {
  22. NSLog(@"Push notification received");
  23. }
  24.  
  25. @implementation AppDelegate
  26.  
  27. @synthesize window, viewController;
  28.  
  29.  
  30.  
  31. - (id)init
  32. {
  33. /** If you need to do any extra app-specific initialization, you can do it here
  34. * -jm
  35. **/
  36. NSHTTPCookieStorage* cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
  37.  
  38. [cookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
  39.  
  40. int cacheSizeMemory = 8 * 1024 * 1024; // 8MB
  41. int cacheSizeDisk = 32 * 1024 * 1024; // 32MB
  42. #if __has_feature(objc_arc)
  43. NSURLCache* sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:cacheSizeMemory diskCapacity:cacheSizeDisk diskPath:@"nsurlcache"];
  44. #else
  45. NSURLCache* sharedCache = [[[NSURLCache alloc] initWithMemoryCapacity:cacheSizeMemory diskCapacity:cacheSizeDisk diskPath:@"nsurlcache"] autorelease];
  46. #endif
  47. [NSURLCache setSharedURLCache:sharedCache];
  48.  
  49. self = [super init];
  50. return self;
  51. }
  52.  
  53. #pragma mark UIApplicationDelegate implementation
  54.  
  55. /**
  56. * This is main kick off after the app inits, the views and Settings are setup here. (preferred - iOS4 and up)
  57. */
  58. - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
  59. {
  60. CGRect screenBounds = [[UIScreen mainScreen] bounds];
  61.  
  62. #if __has_feature(objc_arc)
  63. self.window = [[UIWindow alloc] initWithFrame:screenBounds];
  64. #else
  65. self.window = [[[UIWindow alloc] initWithFrame:screenBounds] autorelease];
  66. #endif
  67. self.window.autoresizesSubviews = YES;
  68.  
  69. #if __has_feature(objc_arc)
  70. self.viewController = [[MainViewController alloc] init];
  71. #else
  72. self.viewController = [[[MainViewController alloc] init] autorelease];
  73. #endif
  74.  
  75. // Set your app's start page by setting the <content src='foo.html' /> tag in config.xml.
  76. // If necessary, uncomment the line below to override it.
  77. // self.viewController.startPage = @"index.html";
  78.  
  79. // NOTE: To customize the view's frame size (which defaults to full screen), override
  80. // [self.viewController viewWillAppear:] in your view controller.
  81.  
  82. self.window.rootViewController = self.viewController;
  83. [self.window makeKeyAndVisible];
  84.  
  85. return YES;
  86. }
  87.  
  88. // this happens while we are running ( in the background, or from within our own app )
  89. // only valid if RistoranteStockholm-Info.plist specifies a protocol to handle
  90. - (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)url
  91. {
  92. if (!url) {
  93. return NO;
  94. }
  95.  
  96. // calls into javascript global function 'handleOpenURL'
  97. NSString* jsString = [NSString stringWithFormat:@"handleOpenURL("%@");", url];
  98. [self.viewController.webView stringByEvaluatingJavaScriptFromString:jsString];
  99.  
  100. // all plugins will get the notification, and their handlers will be called
  101. [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]];
  102.  
  103. return YES;
  104. }
  105.  
  106. // repost the localnotification using the default NSNotificationCenter so multiple plugins may respond
  107. - (void) application:(UIApplication*)application
  108. didReceiveLocalNotification:(UILocalNotification*)notification
  109. {
  110. // re-post ( broadcast )
  111. [[NSNotificationCenter defaultCenter] postNotificationName:CDVLocalNotification object:notification];
  112. }
  113.  
  114. - (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
  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.  
  119. return supportedInterfaceOrientations;
  120. }
  121.  
  122. - (void)applicationDidReceiveMemoryWarning:(UIApplication*)application
  123. {
  124. [[NSURLCache sharedURLCache] removeAllCachedResponses];
  125. }
  126.  
  127.  
  128.  
  129. @end
  130.  
  131. @interface AppDelegate : NSObject <UIApplicationDelegate>
  132.  
  133. @interface AppDelegate <UIApplicationDelegate, PushNotificationDelegate>
  134.  
  135. #import <UIKit/UIKit.h>
  136.  
  137. #import <Cordova/CDVViewController.h>
  138. @interface AppDelegate : NSObject <UIApplicationDelegate>{}
  139.  
  140. // invoke string is passed to your app on launch, this is only valid if you
  141. // edit RistoranteStockholm-Info.plist to add a protocol
  142. // a simple tutorial can be found here :
  143. // http://iphonedevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html
  144.  
  145. @property (nonatomic, strong) IBOutlet UIWindow* window;
  146. @property (nonatomic, strong) IBOutlet CDVViewController* viewController;
  147.  
  148. @end
  149.  
  150. #import <UIKit/UIKit.h>
  151.  
  152. #import <Cordova/CDVViewController.h>
  153.  
  154.  
  155. @interface AppDelegate <UIApplicationDelegate, PushNotificationDelegate>{}
  156.  
  157. // invoke string is passed to your app on launch, this is only valid if you
  158. // edit RistoranteStockholm-Info.plist to add a protocol
  159. // a simple tutorial can be found here :
  160. // http://iphonedevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html
  161.  
  162. @property (nonatomic, strong) IBOutlet UIWindow* window;
  163. @property (nonatomic, strong) IBOutlet CDVViewController* viewController;
  164.  
  165. @end
  166.  
  167. @implementation AppDelegate
  168.  
  169. // Other code
  170.  
  171. - (void) onPushAccepted:(PushNotificationManager *)pushManager withNotification:(NSDictionary *)pushNotification {
  172. NSLog(@"Push notification received");
  173. }
  174.  
  175. @end
  176.  
  177. #import "PushNotificationManager.h"
  178.  
  179. @interface AppDelegate : NSObject <UIApplicationDelegate, PushNotificationDelegate>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement