Reputation: 171
I am facing issue while generating the device token with the real device. I am debugging device and device token is not generating. Sometimes it works and sometimes not.
Please let me know what could be issue. Thanks
Upvotes: 1
Views: 1852
Reputation: 1345
@GopalDevra could you be more clear? Anyway, I have this code for Parse, maybe it's not your case, but you can get the idea.
You can use didRegisterForRemoteNotificationsWithDeviceToken in AppDelegate.m like:
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// Store the deviceToken in the current installation and save it to Parse.
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:deviceToken];
currentInstallation.channels = @[ @"global" ];
[currentInstallation saveInBackground];
}
Edited
Have you put this in didFinishLaunchingWithOptions?
// - Push notifications
// -- Register for Push Notitications
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
//-- Set Notification
if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
{
// iOS 8 Notifications
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[application registerForRemoteNotifications];
}
else
{
// iOS < 8 Notifications
[application registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
}
//--- your custom code
Upvotes: 0
Reputation: 126
As of now, I, too, am having trouble getting device tokens.
My projects stopped generating device tokens when it was "erased" and "installed" around 10 hours ago. Also in the Korean iOS Developers forum, some people have been reporting problems with APNS tokens not generating in the past 10 hours.
There may be something wrong with some of the sandbox APNS servers.
Upvotes: 1
Reputation: 186
Add this method,
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError)
{
print("application:didFailToRegisterForRemoteNotificationsWithError: %@", error)
}
You will get answer, why token is not generated.
Upvotes: 0
Reputation: 31647
Did you put below in didFinishLaunchingWithOptions
of AppDelegate.m
?
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
NSLog(@"ios8 app");
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
NSLog(@"lower ios8 app");
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
}
Upvotes: 1