Registering the iPhone application for push notification not working

27,751

Solution 1

You can try the following:

  • Make sure your Xcode project is configured to use the explicit bundle ID from the provisioning portal
  • Make sure you're not building the target with wildcard or team provisioning profile, check this on the project AND target settings
  • If you created your provisioning profile before configuring the app ID for push, regenerate the provisioning profile

Also look at the error object in the UIApplicationDelegate method

application:didFailToRegisterForRemoteNotificationsWithError:

EDIT 1

Open your provisioning profile in a text editor and look for the string

<key>aps-environment</key>

If your profile does not contain this, it is not correctly set up for push.

Solution 2

Here is my workin code sample from application delegate (AppDelegate.m)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound];
}

To check if registration went OK, implement these three methods

– application:didReceiveRemoteNotification:
– application:didRegisterForRemoteNotificationsWithDeviceToken:
– application:didFailToRegisterForRemoteNotificationsWithError:

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html

Or you can go to Settings to see if there is permissions settings available

like this:

iPad Notification Settings

Solution 3

If this problem appears in production (with your application on the appStore), it's very likely because you created/enabled the APNS production mode of your application AFTER having created the distribution profile.

In this case, no other option but to submit again with a correct certificate...

Rule of thumb: ALWAYS enable/create production certificate for your application BEFORE creating the distribution profile.

You can use the method described by 'nduplessis' (see below) to manually check if you application will run notification once approved.

Share:
27,751
Vinod
Author by

Vinod

Updated on July 23, 2022

Comments

  • Vinod
    Vinod almost 2 years

    I have tried out the example found in the link http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12 , for my iPhone push notification message. I could successfully run all steps except the steps for registering the app for push notification for the first time.

    I have followed different variations of the code:

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

    But none worked for me. I am testing it in my iPhone 4 and my Xode version is 4.2 , OS is Lion. Please advice.

  • Vinod
    Vinod over 12 years
    yes,I have these methods. And also, I have app id with push notification services enabled.
  • Vinod
    Vinod over 12 years
    I have set push notification services under my app id.
  • Vinod
    Vinod over 12 years
    I have added above 3 methods, then I am getting the error in the console "Failed to get token, error: Error Domain=NSCocoaErrorDomain Code=3000 "no valid 'aps-environment' entitlement string found for application" UserInfo=0x143bc0 {NSLocalizedDescription=no valid 'aps-environment' entitlement string found for application}" But the app is running on iPhone with a blank white screen. Also, I have not started the payload/php part of the code.
  • Vinod
    Vinod over 12 years
    1) yes, I have the explicit bundle id 2) I am not using wild cards, 3) I have regenerated provision profile and tried to run the app again.
  • Vinod
    Vinod over 12 years
    I have added NSlog printing for each method, I could get the output from the method "didFinishLaunchingWithOptions" only, and then the above error.
  • Vinod
    Vinod over 12 years
    I am getting the NSlog output for the method "didFinishLaunchingWithOptions" not for others . Now I am getting the error Failed to get token, error: Error Domain=NSCocoaErrorDomain Code=3000 "no valid 'aps-environment' entitlement string found for application" UserInfo=0x1657c0 {NSLocalizedDescription=no valid 'aps-environment' entitlement string found for application}
  • nduplessis
    nduplessis over 12 years
    What error are you getting in the delegate method mentioned above?
  • Marek Sebera
    Marek Sebera over 12 years
    @Vinod great, now when you do have error response, you can find where the problem is. Read this: stackoverflow.com/questions/5681172/…
  • jodm
    jodm over 12 years
    Check you are building against the correct provisioning file. Sounds like the problem to me. You would have had to create a provisioning file against the app Id with push notifications.
  • Vinod
    Vinod over 12 years
    Thank for your point, I have opened the file with extension .mobileprovision, It do not have the line "<key>aps-environment</key>", I think I have to redo the steps and check again.
  • Vinod
    Vinod over 12 years
    Hi Marek, thanks for the link. This is my first app in Iphone. I have one question. I have created a CSR for my first Hello world app for the device. But at that time I have ticked the checkbox "Key pair information" under Certificate assistant. But push notification tutorials do not show it as checked. Should I ticke that checkbox? Should I create separate CSR for each app ?
  • Vinod
    Vinod over 12 years
    Should I create separate CSR for each iphone app ?
  • Vinod
    Vinod over 12 years
    I have recreated the provisioning profile and its working fine now. As you told the problem was with this file. Thanks all.
  • nduplessis
    nduplessis over 12 years
    Happy to hear it. If you find that this answer was the one that solved your problem, please consider accepting it as the correct answer
  • Marek Sebera
    Marek Sebera over 12 years
    @Vinod you're super brave, if your first application ever should use APNS. But really, this question is out of scope of this thread. Create another question, if you're having difficulties with APNS.
  • zirinisp
    zirinisp over 11 years
    In my case I was using the wildcard provisioning profile and that was the problem. Apple can be very complicated some times.
  • AVEbrahimi
    AVEbrahimi about 10 years
    @Vinod No, one CSR is enough