WatchConnectivityを使って以下の様にデータをwatchからiphoneが受信した際にローカル通知を出す様に作りました。UserInfoを使っています。これはBackground transferだという事ですが、アプリがフォアグラウンドになるまで通知が出ませんでした。
以下はAppDelegateに書いています。
Swift
1func session(_ session: WCSession, 2 didReceiveUserInfo userInfo: [String : Any] = [:]) { 3 4 DGcontent.title = "受信!!" 5 //content.subtitle = "受信しました!" 6 DGcontent.body = "受信" 7 DGcontent.sound = UNNotificationSound.default() 8 let DGtrigger = UNTimeIntervalNotificationTrigger(timeInterval: 0.1, repeats: false) 9 let DGrequest = UNNotificationRequest(identifier: "goal", content: DGcontent, trigger: DGtrigger) 10 11 center.delegate = self 12 center.add(DGrequest) { (error) in 13 if let error = error { 14 print(error.localizedDescription) 15 } 16 } 17 18} 19
バックグラウンドで受信して通知を作る事は出来ないのでしょうか?
あなたの回答
tips
プレビュー