gpt4 book ai didi

ios - UIApplication 共享对象未提供预定通知

转载 作者:行者123 更新时间:2023-11-28 08:37:44 27 4
gpt4 key购买 nike

我在我的应用程序中安排了一个通知,并创建了一个带有暂停按钮的可操作通知。在贪睡按钮处理上,我创建了另一个通知并安排了它。但是当我启动应用程序并尝试获取该预定通知时,它说 0 预定通知,并且当我在杀死它后再次启动应用程序时。它发出通知。

怎么了,为什么它没有第一时间给我预定的通知。

func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forLocalNotification notification: UILocalNotification, completionHandler: () -> Void) {

if identifier == Constants.NOTIFICATION_CATEGORY_ACTION_RESUME {
// do something
} else if identifier == Constants.NOTIFICATION_CATEGORY_ACTION_SNOOZE {
// extracting time from notification user info and scheduling another notification of same time
let userInfo = notification.userInfo
let newNotification = UILocalNotification()
let timeInterval = userInfo!["timeInterval"] as! NSTimeInterval
newNotification.fireDate = NSDate(timeIntervalSinceNow: timeInterval)
if #available(iOS 8.2, *) {
newNotification.alertTitle = Utilities.getLocalizedString("NotificationAlertTitle")
} else {
// Fallback on earlier versions
}
newNotification.alertBody = Utilities.getLocalizedString("NotificationAlertBody")
newNotification.alertAction = Utilities.getLocalizedString("NotificationAlertAction")
newNotification.soundName = UILocalNotificationDefaultSoundName
newNotification.category = Constants.CATEGORY_NAME
// use this to store previous time
let date = NSDate()
newNotification.userInfo = [Constants.NOTIFICATIONUSERINFO_TIMEINTERVAL : timeInterval, Constants.NOTIFICATIONUSERINFO_TAG : Constants.NOTIFICATION_TAG, Constants.NOTIFICATIONUSERINFO_SETTIME : date.timeIntervalSince1970]

UIApplication.sharedApplication().cancelAllLocalNotifications()
UIApplication.sharedApplication().scheduleLocalNotification(newNotification)
}
completionHandler()
}

最佳答案

因为你已经使用了这个方法UIApplication.sharedApplication().cancelAllLocalNotifications()。并且此方法取消了所有预定的通知列表。您可以使用 UIApplication.sharedApplication().cancelLocalNotification(YourSpecificNotification) 取消特定的预定通知。在创建新的本地通知时不要调用任何 cancelLocalNotification 方法。

关于ios - UIApplication 共享对象未提供预定通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37300376/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com