あなたはあなたのiOS版アプリの最初に許可を求める必要があります(これはかもしれ
UNUserNotificationCenter.current().requestAuthorization(options: [.alert,.badge,.sound])
{ (granted, error) in
if !granted
{
print("User did not give permissions to send notitications...")
}
}
次に、あなたのwatchOSアプリケーションで、あなたはそれにUUIDを与えることを確認し、将来的にいくつかの時間のための通知を作成することができますwatchOS3のバグ):
let content: UNMutableNotificationContent = UNMutableNotificationContent()
content.title = "Title"
content.subtitle = "Subtitle"
content.body = "message"
content.sound = UNNotificationSound.default()
content.categoryIdentifier = "aCategory"
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: duration, repeats: false)
let id: String = WatchNotify.getUUID()
let request = UNNotificationRequest.init(identifier: id,
content: content,
trigger: trigger)
UNUserNotificationCenter.current().add(request)
{
(error) in // ...
}
....
class func getUUID() -> String
{
let uuidObj = CFUUIDCreate(nil)
let uuidString = CFUUIDCreateString(nil, uuidObj)!
return uuidString as String
}
あなたはWatchOS 3.0府であなたの時計アプリからローカルの通知を投稿することができますWatchOS2.0にないhttps://developer.apple.com/reference/usernotifications – Paulw11