didReceiveRemoteNotification NOT called on IOS 8.2 / Xcode 6.2 - ios

My app not receveing push notification.
I use on IOS 8.2 and registration is:
if([[UIApplication sharedApplication] respondsToSelector:#selector(registerUserNotificationSettings:)]) {
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
I see the server send notification but my device not received...
How can I resolve?

Related

Not able to get Device Token in ios 8

i am not getting into the method
didRegisterForRemoteNotificationsWithDeviceToken
Actually i want to get device token and i have tried to follow this question Get Device Token in iOS 8 but still facing the same problem
.Help me to come out of this problem
Try this.
In your method.
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
use this code
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeNewsstandContentAvailability| UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
And then Put log or breakpoints that your
didRegisterForRemoteNotificationsWithDeviceToken
get called or not.
And if your app is properly registered for remote-notification settings and yet you are not getting device token then
check
didFailToRegisterForRemoteNotificationsWithError
method that will tell you which error you have.
NOTE : device-token will return only when you run on device. OS Simulator doesn't support push notifications
And then also if you are not able to get this method called, then check out this tutorial
http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1
And follow the steps for creating provisioning profile and certificates. I tried with my existing certificate. After you run your app with valid profile as explained in this tutorial series, you will able to get that method called.
There are different way to get device token in iOS 8.
if ([[UIApplication sharedApplication] respondsToSelector:#selector(registerUserNotificationSettings:)]) {
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound];
}
The problem was that there is some kind of restriction in my company network so when i used a wifi device which was not on company network my code worked fine.

UIUserNotificationSettings settingsForTypes: crashing iOS7 Devices

For some reason whenever I try and register for remote notifications on an iOS 7 device my app immediately crashes. I'm running the following block of code:
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0
if ([[UIApplication sharedApplication] respondsToSelector:#selector(registerUserNotificationSettings:)]) {
UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound) categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
#else
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
#endif
Which should allow me to register for notifications in both iOS 8 and 7 without a hitch (as a number of examples I've already found and looked at suggest) but for whatever reason it still crashes. I've narrowed the crash down to to the third line of code I posted--more specifically the following statement: [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound) categories:nil]; If I set it to nil the app runs perfectly fine, but if I leave the line in it just starts crashing.
I've tried putting a log inside the respondsToSelector if statement and the code is definitely not running on iOS 7 devices so I'm somewhat at a loss on what to do.
EDIT:
After a few more hours of troubleshooting I finally managed to find a fix. I needed to import UIKit.framework into my project under Linked Frameworks and Libraries and set it to optional.
I don't know about the #if, cause I've never used them, but I have a very similar code that's working, so you could try this:
if ([[UIApplication sharedApplication] respondsToSelector:#selector(registerUserNotificationSettings:)]) {
// use registerUserNotificationSettings
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
// use registerForRemoteNotificationTypes:
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
}
If that doesn't work for you, perhaps something else is causing the crash.. ninja-style..

Push notifications are not working properly

Me and my team suffering from one month because of this issue, problem is apple push notifications are working for some time in all installed devices, but after that even one device also not getting any notifications, this is happening continuously please solve this problem. Where is that problem and how to resolve this issue, please help me. I've written the below code in didFinishLaunchingWithOptions method of AppDelegate
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
if you want to register for iOS 8 and iOS 7 need to do so in didFinishLaunchingWithOptions:
if ([[UIApplication sharedApplication] respondsToSelector:#selector(registerUserNotificationSettings:)])
{
// iOS 8 Notifications
// use registerUserNotificationSettings
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
// iOS < 8 Notifications
// use registerForRemoteNotifications
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert];
}

didRegisterForRemoteNotificationsWithDeviceToken not called on iOS7

I regularly ask for the notification token with:
if ([application respondsToSelector:#selector(registerUserNotificationSettings:)]) {
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
[application registerForRemoteNotifications];
} else {
[application registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
}
yet the didRegisterForRemoteNotificationsWithDeviceToken callback is consistently called on my iOS 8 iPad and never on my iOS 7 iPhone (not even the didFailToRegisterForRemoteNotificationsWithError one), not even by deleting the app and reinstalling it: nor the alert is displayed. I checked both the certificates and the settings in my iPhone but all seems in order, as well test all the suggestions in SO and all over the internet but nothing seems to fix it. Any more suggestion?
This can be due to a permission deny. Application uninstall does not reset this permission.
In order to verify whether this permission is denied do the following(iOS7):
[[UIApplication sharedApplication] enabledRemoteNotificationTypes] != UIRemoteNotificationTypeNone;
If the permission is denied you will have to do the following steps:
Reset permissions in device settings
Remove the app
Move device clock two days ahead
Restart the phone
Install application and run again
Don't forget to set the clock back after notifications permission popup.
Check the following setting in your Xcode project target:
Target project>Capabilities>Push Notification
Enable the Push Notification and check if you have added the 'Push notification' entitlement to your App Id.
i am using following 'Code' and its working for me.
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
Try this,
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
}
Hope this helps

Need Alternation of registerUserNotificationSettings for iOS Version less than 8.0

I need the code to register UserNotificationSettings in my app for iOS Version Less than 8.0.
I have used the following for iOS 8.0:
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
You need to check if the app contains that method (selector).
if([application respondsToSelector:#selector(registerUserNotificationSettings:)])
{
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert) categories:nil]];
}

Resources