问题
I am working with push notifications in a navBased app. in AppDelegate.m didRegisterForRemoteNotificationsWithDeviceToken: doesn't invoke on calling registerForRemoteNotificationTypes: code looks like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// Get a hex string from the device token with no spaces or < >
NSLog(@"applicationDidFinishLaunchingWithOptions dev token test");
NSString *deviceTokenStr = [[[[deviceToken description]
stringByReplacingOccurrencesOfString: @"<" withString: @""]
stringByReplacingOccurrencesOfString: @">" withString: @""]
stringByReplacingOccurrencesOfString: @" " withString: @""];
NSLog(@"Device Token: %@", deviceTokenStr);
}
I am quite sure that provisioning profile is not the problem. and i found error:
Error in registration. Error: Error Domain=NSCocoaErrorDomain Code=3000 "no valid 'aps-environment' entitlement string found for application" UserInfo=0x115490 {NSLocalizedDescription=no valid 'aps-environment' entitlement string found for application}
can anyone tell me whats going on in this code and y its not working? thanx
回答1:
Check this: link And make sure that you have 5223 port opened.
回答2:
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);
}
回答3:
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.
回答4:
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.
回答5:
After you have generated your Client SSL certificate, create a new provisioning profile containing the App ID you wish to use for notifications.
来源:https://stackoverflow.com/questions/4994302/didregisterforremotenotificationswithdevicetoken-doesnt-invoke-on-calling-regi