IOS - scheduleLocalNotification on production

时间:2015-11-25 14:49:47

标签: ios swift uilocalnotification

我正在从AppDelefate使用scheduleLocalNotification进行UILocalNotification,一切都顺利进行调试。 但是当我在Ad Hoc规定上测试我的应用程序时 - 它不会触发通知。 任何人都可以指导我吗? 谢谢!

1 个答案:

答案 0 :(得分:0)

首先,本地通知不依赖于个人资料。你错过了PushNotifications。

您确定要安排通知吗?也许您忘了请求用户许可?

这应该是这样的:

if #available(iOS 8.0, *) {
  application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound, categories: nil))
  let notification = UILocalNotification()
  notification.alertBody = "body"
  notification.alertAction = "open"
  notification.fireDate = NSDate().dateByAddingTimeInterval(60)
  notification.soundName = UILocalNotificationDefaultSoundName
  notification.userInfo = ["myKey": "myValue"]
  notification.category = "category"
  UIApplication.sharedApplication().scheduleLocalNotification(notification)
} else {
  // do nothing
  // iOS 7 and prior does not require permission
}