user3770039
user3770039

Reputation: 33

Local Notification does not appear after upgrade from iOS 9.x to iOS 10

I am scheduling local notification on iOS 9.x and upgrade the device to iOS 10.

Steps:

  1. Register local notification in iOS 9.x
  2. Schedule local notification on iOS 9.x
  3. Exit app
  4. Upgrade device to iOS 10
  5. Wait for local notification to show up but it fails to appear

Code given below: In didFinsihLaunchingWithOptions

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

Schedule notification code is as follows: if (errorRef != NULL) { *errorRef = nil; }

UILocalNotification * localNot = [[UILocalNotification alloc] init];
localNot.userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
                     self.reminderId, REMINDER_ID_KEY_IN_LOCAL_NOTIF,
                     aOcc.repeatId, REPETITION_ID_KEY_IN_LOCAL_NOTIF,
                     @(index), SNOOZE_INDEX,
                     nil];

localNot.fireDate = [NSDate dateWithTimeInterval:(index * SNOOZE_INTERVAL * 60) sinceDate:aOcc.startTime];
localNot.repeatInterval = aOcc.repeatInterval; // NSCalendarUnitWeekOfYear
localNot.timeZone = aOcc.timeZone; // system timezone


if (aOcc.messageStr != nil  && [aOcc.messageStr length] > 0)
{
    localNot.alertBody = aOcc.messageStr;
}

if (self.soundFlag == YES)
{
    if (self.soundFileName != nil && [self.soundFileName length] > 0)
    {
        localNot.soundName = [[NSString alloc]initWithFormat:@"%@.%@",self.soundFileName,kDefaultSoundFileExtension];
    }
}

[[UIApplication sharedApplication] scheduleLocalNotification:localNot];

if (aOcc.snoozeArray == nil)
{
    aOcc.snoozeArray = @[localNot];
}
else
{
    aOcc.snoozeArray = [aOcc.snoozeArray arrayByAddingObject:localNot];
}
[self.repetitions setObject:aOcc forKey:aOcc.repeatId];
[[RemindersManager sharedInstance] save];
return localNot;

After deep look into logs, I find instance of Sep 28 18:44:05 iPhone SpringBoard(UserNotificationsServer)[57] : [XXXXXXXXXX] Enable notifications: 0 [authorizationOptions: 7]

Please help. Thanks in advance.

Upvotes: 0

Views: 264

Answers (2)

neena-systematix
neena-systematix

Reputation: 61

This code of yours won't work for iOS10. You need to use following for iOS10:

UserNotifications framework

Upvotes: 1

Related Questions