Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Local notifications not working for some users (iOS 8)

I have an app which uses local notifications and ti used to work fine in previous versions. I have updated the app for iOS 8 and tested and worked fine. After submitting the update to app store, a small number of users are complaining that they don't get any local notifications. However, a larger number of users that I've checked are fine and don't observe any issues.

For the users with the error (at least one of them), they can not see the "Notifications" item in the "Settings->myApp" screen; The whole option is missing not that it is disabled. "Location" and "Use Cellular Data" are in that screen but not the Notifications. I have tried to change the settings under "Settings->Notifications->myApp" and it work as expected.

Any suggestions for how to debug this issue would be very helpful. Thanks!

like image 238
Mikrasya Avatar asked Nov 03 '14 15:11

Mikrasya


2 Answers

Try this for Objective-C:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:    (NSDictionary *)launchOptions
{
// are you running on iOS8?
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) 
  {
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge|UIUserNotificationTypeAlert|UIUserNotificationTypeSound) categories:nil];
    [application registerUserNotificationSettings:settings];
  } 
else // iOS 7 or earlier
  {
    UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
    [application registerForRemoteNotificationTypes:myTypes];
  }
}

For Swift:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
// Override point for customization after application launch.
 if(UIApplication.instancesRespondToSelector(Selector("registerUserNotificationSettings:")))
 {
    application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound | UIUserNotificationType.Alert | UIUserNotificationType.Badge, categories: nil))
 }
 else
 {
    //
 }
return true
}
like image 104
Nagarjun Avatar answered Nov 15 '22 17:11

Nagarjun


First You have to Register to Use Local Push Notification

UIApplication *application = [UIApplication sharedApplication];
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
    [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
}

then you can send Local Push Notification By This

 UILocalNotification *notification = [UILocalNotification new];
notification.alertBody = @"Local Push !!!";
notification.applicationIconBadgeNumber=1;
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
like image 34
khaled Avatar answered Nov 15 '22 18:11

khaled