2017-06-19 43 views
0

我正在开发苹果手表应用程序,它具有每2或3或5分钟后在之后向用户显示通知的功能。UNUserNotification是否可以选择仅在苹果手表上显示通知?

我已通过iOS UNUserNotification及其作品完美实现了此功能。

但我想在这里是用户可以看到所有通知只在苹果手表不在iPhone上。

是否可以仅在Apple手表上显示通知?

在此先感谢!

我已经使用下面的代码UserNotification

func scheduleNotification(at date: Date) { 


     let trigger = UNTimeIntervalNotificationTrigger(timeInterval: (1*60), repeats: true) 

     let content = UNMutableNotificationContent() 
     content.title = "Test Reminder" 
     content.body = "Show More detail in Body!" 
     content.sound = UNNotificationSound.default() 
     content.categoryIdentifier = "myCategory" 

     if let path = Bundle.main.path(forResource: "logo", ofType: "png") { 
      let url = URL(fileURLWithPath: path) 

      do { 
       let attachment = try UNNotificationAttachment(identifier: "logo", url: url, options: nil) 
       content.attachments = [attachment] 
      } catch { 
       print("The attachment was not loaded.") 
      } 
     } 

     let request = UNNotificationRequest(identifier: "textNotification", content: content, trigger: trigger) 

     UNUserNotificationCenter.current().delegate = self 
     UNUserNotificationCenter.current().removeAllPendingNotificationRequests() 
     UNUserNotificationCenter.current().add(request) {(error) in 
      if let error = error { 
       print("Uh oh! We had an error: \(error)") 
      } 
     } 
    } 

回答

2

不,这是不可能的。 系统自动决定在哪里显示通知,开发人员无法控制这一点。 如果配对的iPhone已锁定且手表已被用户佩戴,则该通知将显示在Apple Watch上。在任何其他情况下,通知将显示在iPhone上。

请参阅Notifications on your Apple Watch

相关问题