Reputation: 85
How do I obtain the device token? I am trying to add it and I can't seem to understand. What do I need to do? Where do I go? What do I need to get this?
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)newDeviceToken
{
// Tell Parse about the device token.
[PFPush storeDeviceToken:newDeviceToken];
// Subscribe to the global broadcast channel.
[PFPush subscribeToChannelInBackground:@""];
}
Upvotes: 1
Views: 4264
Reputation: 10759
You need to call this in app delegate.
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)];
Make sure app delegate has this function
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)_deviceToken {
// Get a hex string from the device token with no spaces or < >
NSString *deviceToken = [[[[_deviceToken description]
stringByReplacingOccurrencesOfString: @"<" withString: @""]
stringByReplacingOccurrencesOfString: @">" withString: @""]
stringByReplacingOccurrencesOfString: @" " withString: @""];
}
Upvotes: 1
Reputation: 22873
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)_deviceToken {
// Get a hex string from the device token with no spaces or < >
NSString *deviceToken = [[[[_deviceToken description]
stringByReplacingOccurrencesOfString: @"<" withString: @""]
stringByReplacingOccurrencesOfString: @">" withString: @""]
stringByReplacingOccurrencesOfString: @" " withString: @""];
}
Upvotes: 5
Reputation: 129657
You call registerForRemoteNotificationTypes:
when your app launches, then the system calls back into your app via the application:didRegisterForRemoteNotificationsWithDeviceToken:
method (which you must implement). The newDeviceToken
variable will have the device token.
See the documentation for the UIApplication
class.
Upvotes: 1