Loading Example/www/index.html +35 −9 Changes for Example/www/index.html: 35 added lines, 9 removed lines. Original line number Diff line number Diff line Loading @@ -4,6 +4,8 @@ <title>com.PhoneGap.c2dm</title> </head> <body> <!--<script type="text/javascript" charset="utf-8" src="cordova-2.2.0.js"></script>--> <script type="text/javascript" charset="utf-8" src="phonegap.js"></script> <script type="text/javascript" charset="utf-8" src="jquery_1.5.2.min.js"></script> <script type="text/javascript" src="PushNotification.js"></script> Loading @@ -14,28 +16,51 @@ function onDeviceReady() { $("#app-status-ul").append('<li>deviceready event received</li>'); try { pushNotification = window.plugins.pushNotification; if (device.platform == 'android' || device.platform == 'Android') { $("#app-status-ul").append('<li>registering android</li>'); pushNotification.register(successHandler, errorHandler, {"senderID":"661780372179","ecb":"onNotificationGCM"}); } else { $("#app-status-ul").append('<li>registering iOS</li>'); pushNotification.register(tokenHandler, errorHandler, {"badge":"true","sound":"true","alert":"true","ecb":"onNotificationAPN"}); } } catch(err) { txt="There was an error on this page.\n\n"; txt+="Error description: " + err.message + "\n\n"; alert(txt); } } // handle APNS notifications for iOS function onNotificationAPN(event) { if (event.alert) { $("#app-status-ul").append('<li>push-notification: ' + event.alert + '</li>'); navigator.notification.alert(event.alert); } function onNotificationAPN(e) { if (e.foreground) { $("#app-status-ul").append('<li>--INLINE NOTIFICATION--' + '</li>'); if (event.sound) { var snd = new Media(event.sound); if (e.sound) { var snd = new Media(e.sound); snd.play(); } if (event.badge) { pushNotification.setApplicationIconBadgeNumber(successHandler, event.badge); if (e.alert) { $("#app-status-ul").append('<li>push-notification: ' + e.alert + '</li>'); navigator.notification.alert(e.alert); } } else { $("#app-status-ul").append('<li>--BACKGROUND NOTIFICATION--' + '</li>'); if (e.alert) { $("#app-status-ul").append('<li>push-notification: ' + e.alert + '</li>'); } } if (e.badge) { pushNotification.setApplicationIconBadgeNumber(successHandler, e.badge); } } Loading Loading @@ -85,6 +110,7 @@ function tokenHandler (result) { $("#app-status-ul").append('<li>token: '+ result +'</li>'); console.log("token = " + result); // Your iOS push server needs to know the token before it can push to this device // here is where you might want to send it the token for later use. } Loading src/ios/AppDelegate+notification.m +1 −0 Changes for src/ios/AppDelegate+notification.m: 1 added line, 0 removed lines. Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ static char launchNotificationKey; if (appState == UIApplicationStateActive) { PushPlugin *pushHandler = [self getCommandInstance:@"PushPlugin"]; pushHandler.notificationMessage = [userInfo objectForKey:@"aps"]; pushHandler.isInline = YES; [pushHandler notificationReceived]; } else { //save it for later Loading src/ios/PushPlugin.h +2 −0 Changes for src/ios/PushPlugin.h: 2 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ @interface PushPlugin : CDVPlugin { NSDictionary *notificationMessage; BOOL isInline; NSString *notificationCallbackId; NSString *callback; Loading @@ -40,6 +41,7 @@ @property (nonatomic, copy) NSString *callback; @property (nonatomic, retain) NSDictionary *notificationMessage; @property BOOL isInline; - (void)register:(NSMutableArray *)arguments withDict:(NSMutableDictionary *)options; Loading src/ios/PushPlugin.m +9 −0 Changes for src/ios/PushPlugin.m: 9 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ @implementation PushPlugin @synthesize notificationMessage; @synthesize isInline; @synthesize callbackId; @synthesize notificationCallbackId; Loading Loading @@ -70,6 +71,8 @@ if (notificationTypes == UIRemoteNotificationTypeNone) NSLog(@"PushPlugin.register: Push notification type is set to none"); isInline = NO; [[UIApplication sharedApplication] registerForRemoteNotificationTypes:notificationTypes]; } Loading Loading @@ -163,6 +166,12 @@ if ([notificationMessage objectForKey:@"badge"]) [jsonStr appendFormat:@"badge:%d,", [[notificationMessage objectForKey:@"badge"] intValue]]; if (isInline) { [jsonStr appendFormat:@"foreground:'%d',", 1]; isInline = NO; } if ([notificationMessage objectForKey:@"sound"]) [jsonStr appendFormat:@"sound:'%@',", [notificationMessage objectForKey:@"sound"]]; Loading Loading
Example/www/index.html +35 −9 Changes for Example/www/index.html: 35 added lines, 9 removed lines. Original line number Diff line number Diff line Loading @@ -4,6 +4,8 @@ <title>com.PhoneGap.c2dm</title> </head> <body> <!--<script type="text/javascript" charset="utf-8" src="cordova-2.2.0.js"></script>--> <script type="text/javascript" charset="utf-8" src="phonegap.js"></script> <script type="text/javascript" charset="utf-8" src="jquery_1.5.2.min.js"></script> <script type="text/javascript" src="PushNotification.js"></script> Loading @@ -14,28 +16,51 @@ function onDeviceReady() { $("#app-status-ul").append('<li>deviceready event received</li>'); try { pushNotification = window.plugins.pushNotification; if (device.platform == 'android' || device.platform == 'Android') { $("#app-status-ul").append('<li>registering android</li>'); pushNotification.register(successHandler, errorHandler, {"senderID":"661780372179","ecb":"onNotificationGCM"}); } else { $("#app-status-ul").append('<li>registering iOS</li>'); pushNotification.register(tokenHandler, errorHandler, {"badge":"true","sound":"true","alert":"true","ecb":"onNotificationAPN"}); } } catch(err) { txt="There was an error on this page.\n\n"; txt+="Error description: " + err.message + "\n\n"; alert(txt); } } // handle APNS notifications for iOS function onNotificationAPN(event) { if (event.alert) { $("#app-status-ul").append('<li>push-notification: ' + event.alert + '</li>'); navigator.notification.alert(event.alert); } function onNotificationAPN(e) { if (e.foreground) { $("#app-status-ul").append('<li>--INLINE NOTIFICATION--' + '</li>'); if (event.sound) { var snd = new Media(event.sound); if (e.sound) { var snd = new Media(e.sound); snd.play(); } if (event.badge) { pushNotification.setApplicationIconBadgeNumber(successHandler, event.badge); if (e.alert) { $("#app-status-ul").append('<li>push-notification: ' + e.alert + '</li>'); navigator.notification.alert(e.alert); } } else { $("#app-status-ul").append('<li>--BACKGROUND NOTIFICATION--' + '</li>'); if (e.alert) { $("#app-status-ul").append('<li>push-notification: ' + e.alert + '</li>'); } } if (e.badge) { pushNotification.setApplicationIconBadgeNumber(successHandler, e.badge); } } Loading Loading @@ -85,6 +110,7 @@ function tokenHandler (result) { $("#app-status-ul").append('<li>token: '+ result +'</li>'); console.log("token = " + result); // Your iOS push server needs to know the token before it can push to this device // here is where you might want to send it the token for later use. } Loading
src/ios/AppDelegate+notification.m +1 −0 Changes for src/ios/AppDelegate+notification.m: 1 added line, 0 removed lines. Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ static char launchNotificationKey; if (appState == UIApplicationStateActive) { PushPlugin *pushHandler = [self getCommandInstance:@"PushPlugin"]; pushHandler.notificationMessage = [userInfo objectForKey:@"aps"]; pushHandler.isInline = YES; [pushHandler notificationReceived]; } else { //save it for later Loading
src/ios/PushPlugin.h +2 −0 Changes for src/ios/PushPlugin.h: 2 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ @interface PushPlugin : CDVPlugin { NSDictionary *notificationMessage; BOOL isInline; NSString *notificationCallbackId; NSString *callback; Loading @@ -40,6 +41,7 @@ @property (nonatomic, copy) NSString *callback; @property (nonatomic, retain) NSDictionary *notificationMessage; @property BOOL isInline; - (void)register:(NSMutableArray *)arguments withDict:(NSMutableDictionary *)options; Loading
src/ios/PushPlugin.m +9 −0 Changes for src/ios/PushPlugin.m: 9 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ @implementation PushPlugin @synthesize notificationMessage; @synthesize isInline; @synthesize callbackId; @synthesize notificationCallbackId; Loading Loading @@ -70,6 +71,8 @@ if (notificationTypes == UIRemoteNotificationTypeNone) NSLog(@"PushPlugin.register: Push notification type is set to none"); isInline = NO; [[UIApplication sharedApplication] registerForRemoteNotificationTypes:notificationTypes]; } Loading Loading @@ -163,6 +166,12 @@ if ([notificationMessage objectForKey:@"badge"]) [jsonStr appendFormat:@"badge:%d,", [[notificationMessage objectForKey:@"badge"] intValue]]; if (isInline) { [jsonStr appendFormat:@"foreground:'%d',", 1]; isInline = NO; } if ([notificationMessage objectForKey:@"sound"]) [jsonStr appendFormat:@"sound:'%@',", [notificationMessage objectForKey:@"sound"]]; Loading