Advertisement
Guest User

Untitled

a guest
Nov 25th, 2014
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  2.  
  3. // Override point for customization after application launch.
  4.  
  5. // Add the view controller's view to the window and display.
  6. [self.window addSubview:viewController.view];
  7. [self.window makeKeyAndVisible];
  8.  
  9. NSLog(@"Registering for push notifications...");
  10. [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
  11. (UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
  12. return YES;
  13.  
  14. }
  15.  
  16. - (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  17.  
  18. NSString *str = [NSString stringWithFormat:@"Device Token=%@",deviceToken];
  19. NSLog(@"This is device token%@", deviceToken);
  20.  
  21. }
  22.  
  23. - (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
  24.  
  25. NSString *str = [NSString stringWithFormat: @"Error: %@", err];
  26. NSLog(@"Error %@",err);
  27.  
  28. }
  29.  
  30. - (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
  31. {
  32. NSString *token = [[deviceToken description] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"<>"]];
  33. token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
  34. NSLog(@"content---%@", token);
  35. }
  36.  
  37. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  38. [self.window addSubview:viewController.view];
  39. [self.window makeKeyAndVisible];
  40.  
  41. NSLog(@"Registering for push notifications...");
  42. [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
  43. (UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
  44. return YES;
  45. }
  46.  
  47. - (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  48. NSString *str = [NSString stringWithFormat:@"Device Token=%@",deviceToken];
  49. NSLog(@"%@", str);
  50. }
  51.  
  52. - (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
  53. NSString *str = [NSString stringWithFormat: @"Error: %@", err];
  54. NSLog(@"%@",str);
  55. }
  56.  
  57. // Prepare the Device Token for Registration (remove spaces and < >)
  58. NSString *devToken = [[[[deviceToken description]
  59. stringByReplacingOccurrencesOfString:@"<"withString:@""]
  60. stringByReplacingOccurrencesOfString:@">" withString:@""]
  61. stringByReplacingOccurrencesOfString: @" " withString: @""];
  62.  
  63.  
  64. NSString *str = [NSString
  65. stringWithFormat:@"Device Token=%@",devToken];
  66. UIAlertView *alertCtr = [[[UIAlertView alloc] initWithTitle:@"Token is " message:devToken delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
  67. [alertCtr show];
  68. NSLog(@"device token - %@",str);
  69.  
  70. NSString *deviceTokenString = deviceToken.description;
  71. deviceTokenString = [deviceTokenString stringByReplacingOccurrencesOfString:@"[< >]" withString:@"" options:NSRegularExpressionSearch range:NSMakeRange(0, deviceTokenString.length)];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement