Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Registering the iPhone application for push notification not working

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.

like image 957
Vinod Avatar asked Jan 17 '12 10:01

Vinod


People also ask

Why push notification is not working for iOS?

You can fix an iPhone that's not getting notifications by restarting it or making sure notifications are turned on. You should also make sure your iPhone is connected to the internet so apps can receive notifications. If all else fails, you should try resetting the iPhone — just make sure to back it up first.

Why are my push notifications not working?

Check Settings > Notifications & Actions > Turn on Get notifications from apps and other senders. Make sure your site and browser are also enabled.

How do I enable push notifications for apps on iPhone?

Go to Settings and tap Notifications. Select an app under Notification Style. Under Alerts, choose the alert style you want. If you turn on Allow Notifications, you can choose when you want the notifications to be delivered – immediately or in the scheduled notification summary.


2 Answers

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.

like image 167
nduplessis Avatar answered Oct 19 '22 23:10

nduplessis


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

like image 30
Marek Sebera Avatar answered Oct 20 '22 01:10

Marek Sebera