Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
  2. {
  3. NSLog(@"My token is: %@", deviceToken);
  4. }
  5.  
  6. - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
  7. {
  8. NSLog(@"Calling push notification next, my registered token is: %@", deviceToken);
  9. // Code for phonegap communication - calls this method in PushNotification.m
  10. PushNotification* pushHandler = [self.viewController getCommandInstance:@"PushNotification"];
  11. [pushHandler didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
  12. }
  13.  
  14. - (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  15. NSLog(@"didRegisterForRemoteNotificationsWithDeviceToken:%@", deviceToken);
  16. DLog(@"didRegisterForRemoteNotificationsWithDeviceToken:%@", deviceToken);
  17.  
  18. NSString *token = [[[[deviceToken description] stringByReplacingOccurrencesOfString:@" <"withString:@""]
  19. stringByReplacingOccurrencesOfString:@">" withString:@""]
  20. stringByReplacingOccurrencesOfString: @" " withString: @""];
  21.  
  22. NSMutableDictionary *results = [PushNotification getRemoteNotificationStatus];
  23. [results setValue:token forKey:@"deviceToken"];
  24. CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:results];
  25. [self writeJavascript:[pluginResult toSuccessCallbackString:[self.callbackIds valueForKey:@"registerDevice"]]];
  26.  
  27. }
  28.  
  29. register: function() {
  30. var pushNotification = window.plugins.pushNotification;
  31. pushNotification.registerDevice({alert:true, badge:true, sound:true}, function(status) {
  32. app.myLog.value+=JSON.stringify(['registerDevice status: ', status])+"n";
  33. app.storeToken(status.deviceToken);
  34. });
  35. },
  36. storeToken: function(token) {
  37. console.log("Token is " + token);
  38. ...
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement