Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

didRegisterForRemoteNotificationsWithDeviceToken: doesn't invoke on calling registerForRemoteNotificationTypes:?

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

like image 320
Piscean Avatar asked Feb 14 '11 16:02

Piscean


4 Answers

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);
}
like image 126
kshitij godara Avatar answered Oct 25 '22 22:10

kshitij godara


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

like image 45
Max Avatar answered Oct 26 '22 00:10

Max


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.

like image 22
dklt Avatar answered Oct 25 '22 22:10

dklt


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.

like image 36
user1323655 Avatar answered Oct 25 '22 23:10

user1323655