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.
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.
Check Settings > Notifications & Actions > Turn on Get notifications from apps and other senders. Make sure your site and browser are also enabled.
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.
You can try the following:
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.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With