Reputation: 8381
I am developing apple watch app which have the functionality to show a notification to User after every 2 or 3 or 5 min.
I have achieved this functionality through iOS UNUserNotification
and its works perfectly.
But what I want here is User can see all notifications only on Apple watch not on iPhone.
Right now it's showing on both iPhone & Apple watch.
Is it possible to show notifications only on the Apple watch?
I have implemented the below code for 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)")
}
}
}
Thanks in Advance!
Upvotes: 1
Views: 668
Reputation: 271
Yes, you can make the notification appear only on watch if you will trigger the Local notification from WatchKit Extension. Please see the corresponding documentation: https://developer.apple.com/documentation/watchkit/notifications/taking_advantage_of_notification_forwarding?changes=__5
Upvotes: 0
Reputation: 54795
No, this is not possible. The system decides automatically where to show the notifications, developers have no control over this. The notification will be displayed on the Apple Watch if the paired iPhone is locked and the Watch is worn by the user. In any other case, the notification will be displayed on the iPhone.
See Notifications on your Apple Watch
Upvotes: 2