私はWatchOS 3ベータ版を使用しており、時計のローカル通知を開始しようとしています。インターフェイスは、以下のコードで "buttonPushed"メソッドを呼び出すボタンの1つです。アプリは正常に動作しますが、通知はありません。アプリケーション構造は、WatchKitアプリケーションのXcode 8のデフォルトです。WatchOS 3のローカル通知
このコードは、私は完全に何かを明らかに足りないWatchKit拡張子
のInterfaceController.swiftファイル内にありますか?
@IBAction func buttonPushed() {
sendMyNotification()
}
func sendMyNotification(){
if #available(watchOSApplicationExtension 3.0, *) {
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .sound]) { (granted, error) in
// Enable or disable features based on authorization.
}
let content = UNMutableNotificationContent()
content.title = NSString.localizedUserNotificationString(forKey: "Hello!", arguments: nil)
content.body = NSString.localizedUserNotificationString(forKey: "Hello_message_body", arguments: nil)
content.sound = UNNotificationSound.default()
content.categoryIdentifier = "REMINDER_CATEGORY"
// Deliver the notification in five seconds.
let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: 5, repeats: false)
let request = UNNotificationRequest.init(identifier: "FiveSecond", content: content, trigger: trigger)
// Schedule the notification.
center.add(request ,withCompletionHandler: nil)
} else {
// Fallback on earlier versions
}
}
また 'ID = UUID.init()聞かせて使用するユニークな識別文字列を作成することができます。uuidString' –
一生に一度それは2つの同じUUIDかもしれません。 – Vladimir