我正在iOS 9.x上安排本地通知,并将设备升级到iOS 10。
步骤:
以下代码:didFinsihLaunchingWithOptions
if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)])
{
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeSound|UIUserNotificationTypeBadge categories:nil]];
}
日程安排通知代码如下: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;
深入研究日志后,我找到了实例 9月28日18:44:05 iPhone SpringBoard(UserNotificationsServer)[57]:[XXXXXXXXXX]启用通知:0 [authorizationOptions:7]
请帮忙。提前谢谢。
答案 0 :(得分:1)
您的此代码不适用于iOS10。 iOS10需要使用以下内容:
UserNotifications framework
答案 1 :(得分:0)
在iOS 10中,您必须使用UserNotifications
框架
以下是您可以查看的链接
示例:
https://www.appcoda.com/ios10-user-notifications-guide/
https://useyourloaf.com/blog/local-notifications-with-ios-10/