didRegisterForRemoteNotificationsWithDeviceToken: doesn't invoke on calling registerForRemoteNotificationTypes:?

爱⌒轻易说出口 提交于 2019-11-30 18:41:16
Max

Check this: link And make sure that you have 5223 port opened.

kshitij godara

Enter this code in Appdelegate didFinishLaunching method this -

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
     (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

and then just also copy and paste these two methods in same appdelegate -

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
    NSLog(@"My token is: %@", deviceToken);
        NSString *dToken = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
    dToken = [dToken stringByReplacingOccurrencesOfString:@" " withString:@""];


    NSLog(@"STR%@",dToken);


- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{

    NSLog(@"Failed to get token, error: %@", error);
}

I had that exact error previously """"no valid 'aps-environment' entitlement string found for application"""".

To resolve it, you need a specific code-signing profile with the right App ID for APNS to work (ie: not a .* profile). Google around, you can probably find some step-by-step guides on how to resolve it properly.

If you keep seeing that error in log, try deleting profile on your iOS devices under >Settings>General>Profiles and re-examine them in organizer.

Open the mobileprovisioning profile you use for your app and look for the "aps-environment" string there. It should be set to "development" or "production".

The error you receive means you don't have this string in the profile, therefore the app is simply not allowed to register for push notifications. This will happen if you have created the profile before configuring push notifications for App ID.

If you don't see the string - recreate (delete/create new) mobileprovisioning profile on the iOS Developers Portal. that will solve the problem.

Also make sure when you submit to AppStore you recreate provisioning AppStore profile for your app as well. It must contain the same "aps-environment" string AND it is not there by default if you created AppStore provisioning profile before you configured push notifications for your APP ID.

After you have generated your Client SSL certificate, create a new provisioning profile containing the App ID you wish to use for notifications.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!