Reputation: 33
I am scheduling local notification on iOS 9.x and upgrade the device to iOS 10.
Steps:
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
Reputation: 3708
In iOS 10 you have to UserNotifications
framework
Here is the links you can check
Examples:
https://www.appcoda.com/ios10-user-notifications-guide/
https://useyourloaf.com/blog/local-notifications-with-ios-10/
Upvotes: 0
Reputation: 61
This code of yours won't work for iOS10. You need to use following for iOS10:
UserNotifications framework
Upvotes: 1