On iOS, we can register for push notifications using the registerForRemoteNotifications method on UIApplication.
I want to create a watchOS 2 app that will work even if my watch is not connected to my phone (but is connected to Wi-Fi). I would like to send push notifications from a server to the watch directly. Is there a way to do this?
If so, what are the equivalent of these methods in a watchOS 2 extension?
application.registerForRemoteNotifications
application(:, didRegisterForRemoteNotificationsWithDeviceToken:)
application(:, didFailToRegisterForRemoteNotificationsWithError:)
application(:, didReceiveRemoteNotification:)
If not, what are my other options?
Currently there is no way to directly get notification from server on watch. As mentioned in Notification Essentials for watch
Apple Watch displays local and remote notifications only if the
containing iOS supports them. For information about how to support
local and remote notifications in your iOS app, see Local and Remote
Notification Programming Guide.
This also mentioned that
When one of your app’s local or remote notifications arrives on the
user’s iPhone, iOS decides whether to display that notification on the
iPhone or on the Apple Watch
Now there are some scenrio in this, if your phone is active and notification arrives, it will be received on phone. but if phone is locked and watch is active and then notification arrived it will be displayed on watch.
It is also mentioned in Apple Push Notification Service Doc that
Apple Push Notification service (APNs) is the centerpiece of the
remote notifications feature. It is a robust and highly efficient
service for propagating information to iOS (and, indirectly, watchOS),
tvOS, and OS X devices.
Related
if My app works at background, can I use silent push to wake app and get the VOIP call?
I used "jpush" to post a silent push which can work when connecting my idevice with Xcode and run APP.
If my idevice doesn't run APP with Xcode, I can not receive the silent push at background (only receive at foreground.)
Is it possible to use silent push to wake up APP and get VOIP call?
Did I get something wrong??
Yes. If your application does VoIP calling then it's possible to use PushKit:
Overview
The PushKit framework sends specific types of notifications — such as VoIP invitations, [...] — directly to your app for processing. [...]
Unlike user notifications, which are supported by the UserNotifications framework, PushKit notifications are never presented to the user — they don't present badges, alerts, or sounds.
PushKit notifications offer the following advantages over user notifications:
If your app isn't running, the system automatically launches it upon receiving the notification. [...] For more information, see Local and Remote Notification Programming Guide.
Your app is given runtime to process the notification, even if it's running in the background.
[...]
I am trying to make an app where you could send a warning to other users which then will trigger an alarm on the receivers phone.
So my plan is to send a silent warning to the receiver, which then triggers sounds and vibrations on the receivers phone from the app.
So basically my question is, is it possible to open an app on a phone through a silent push?
This is done with push notifications in iOS. See Apple's description.
Apps must be configured appropriately before they can receive local or remote notifications. The configuration process differs slightly on iOS and OS X, but the basic principles are the same. At launch time, your app registers to receive notifications and works with the system to configure that notification support. Once registration is complete, you can start creating notifications for delivery to your app. Your app then handles these incoming notifications and provides an appropriate response.
But note that it is up to the receiving user to determine how he wants to be alerted.
I see this in the Apple Watch Programming Guide:
When one of your app’s local or remote notifications arrives on the
user’s iPhone, iOS decides whether to display that notification on the
iPhone or on the Apple Watch.
Is there a way to make a notification only appear on the watch?
This was not possible until watchOS 3.
watchOS 3 introduces the User Notifications framework, which supports the delivery and handling of local and remote notifications. You can use the classes of this framework to schedule the delivery of local notifications based on specific conditions, such as a date or time or after a time interval, and to receive and handle local and remote notifications when they are delivered to the user’s device.
You can now schedule a local notification on the watch, and the notification is (delivered to and) only handled by the watch. It will not appear on the phone.
For more information, see the WWDC 2016 Introduction to Notifications, and Quick Interaction Techniques for watchOS sessions.
Useful picture from this guide:
Unfortunately no, with watch apps you now need to handle notifications in 3 places. When the app is running, application:didReceiveLocalNotification: is called. When the phone is unlocked the notification is sent to the notification center and you'll need to handle the user selecting it in application:didFinishLaunchingWithOptions:. The watch will automatically handle any notification its containing app gets, displaying the app and the alert's body. If you want a custom notification you'll need to setup a notification category in the containing app and a dynamic notification in the watch. If you're trying to just get information from the app to the watch you can use the app groups dictionary or the openParentApplication:reply: method.
Nope. It's completely controlled by the OS.
Whatever you can do on the watch app, you can check it from this relatively simple documentation:https://developer.apple.com/library/ios/documentation/General/Conceptual/WatchKitProgrammingGuide/
And I don't think you can do something like what you say. We have to admit that there are a lots limitations in this version of WatchKit.
I want to display all the notifications delivered (To IOS Device) within my application.
So how would I get all notifications objects when app is switching from dead to active state?
I am using urban air ship for push notification.
Can I retrieve previous notifications delivered when app is in dead state in "didFinishLaunchingWithOptions:(NSDictionary *)launchOptions"?
According to me there is no possibility.
You can't access notification object until User interact with notification from Notification Center or App is in foreground.
You may check which method is calling when push notification arrives in this SO Answer.
You may search for list of push sent in Urban Airship Document. You may find something in their document or can connect their support team.
I have a small question about push notification sync between devices.
For instance, I'm building an iOS and an OSX app.
Both of them support push notifications and I send notifications to both devices at the same time.
Is it possible to "hide/dismiss" the push notification (or change badge) on an OSX device if I opened a push notification on my iOS device?
Like iMessages does.
I can't find any Apple API or third party service that does somthing like that.
Thanks for your help.
Does your app communicating with any server? If yes you can send information like "user-saw-content" to the server then send another push notification to cancel others notifcations if necessary.