How to use Apple watch PushNotificationPayload.apns - apple-watch

I'm trying to understand the usage of PushNotificationPayload.apns
From what I understand, I can only specify this file if running through the simulator. If that's the case, how am I supposed to receive remote notifications? Since when does the simulator support remote notifications? And even if it does, how do I get the device token from it?
Thanks

PushNotificationPayload.apns is indeed usable in the simulator only. It is actually useful because the Simulator does not support push notification.
It is simply a file containing a Push Notification payload that can be used to simulate receiving a push notification on the Simulator.
You can tell the simulator this payload should be used in your tests by editing your WatchKit App scheme, setting the Watch Interface to Dynamic or Static Notification. Then you’ll be able to specify which payload to use for the notification view.

Related

Watchkit - How to schedule notification only for Apple Watch?

I have created an App with Apple Watch extension.
I would like to know if it's possible to schedule a notification that only appears on the Apple Watch. And conversely, can we schedule a notification to only appear on the iPhone?
This is a great question, but unfortunately it is not possible at this time. Apple is trying to be very pragmatic about how they direct notifications. If you iPhone is unlocked, they assume you are looking at it and will route notifications there. If you iPhone is locked, then all notifications will be routed to your Apple Watch. They want to avoid duplicated notifications in both locations at all costs.
Currently there is no ability to force route remote or local notifications directly to the Watch only. If you feel strongly about this feature, then I would suggest you file an enhancement radar with the Apple Bug Reporting System.
In the official Apple documentation they said that:
Apple Watch takes full advantage of the existing interactive
notification support on iOS. If your iOS app supports notifications,
Apple Watch displays those notifications at appropriate times. 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. For notifications sent to Apple Watch, the
system lets the the user know subtly that a notification is available.
If the user chooses to view the notification, the system displays an
abbreviated version of the notification first, followed by a more
detailed version. The user can dismiss the detailed notification,
launch your WatchKit app, or act on the notification by tapping an
available action button.
https://developer.apple.com/library/ios/documentation/General/Conceptual/WatchKitProgrammingGuide/BasicSupport.html
So I think you can tell to iOS the behavior of your notifications (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. For notifications sent to Apple Watch, the
system lets the the user know subtly that a notification is available.)

How are iPhone apps able to generate notifications while in standby?

I'm a bit confused.
It says on many places, that on IOS you can't make your app work if the phone enters standby mode unless you use push notifications.
I did encounter some apps that do succeed this in IPhone 4
(such as ihandy alarm clock http://www.ihandysoft.com/alarm_clock.html)
It even beeped on standby when I was in airplane mode!
Can someone straighten my thought regarding this issue?
There are two kinds of notification in iOS: push notification and local notification.
In your case, the app beeps while airplane mode is on, it might use local notification rather than push notification.
According to http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html, “Apps that receive regular updates from external accessories” can continue to run in the background.

Retrieving latest Push Notification if app was not launched by hitting the 'View' button

I'm wondering if there is any way of retrieving the last-received push notification if the app is launched from the home screen instead of by pressing the 'View' button on the notification.
The app we're writing is for dealing with sensitive data, and it's important to be able for the central server to be able to remotely disable a client at will, without having the requirement that the app needs an internet connection to launch.
The basic idea I came up for this would be to send a push notification with a custom payload letting the app know to disable itself until it can properly sync its data.
This would work if the user pressed View on the notification, but not if they cancelled it and then launched the app separately.
I'd love to know if this is possible, or otherwise if there's a better way to implement this functionality.
It's not possible. Your app would have to connect to the server on launch and get its latest status from there. If your use case is that sensitive, push notifications are probably not reliable enough anyway because Apple does not guarantee that a push notification will actually be delivered.
Like Ole said, not possible.
Note that you shouldn't be relying on push notifications for anything like this. From Apple's push notifications programming guide:
Remember that delivery of notifications is “best effort” and is not guaranteed.

iPhone real time notification from a server, without using Apple push notification

I'm looking for a way to get real time notification from a server in an iPhone App. I don't want to use Apple Push Notification as I have many notifications. My web service is coded in PHP, and I haven't figured out an easy way to implement this functionnality. Any idea what should I do?
Thx a lot for your help!
EDIT : I'm looking for a way to get notification only when the app is launched (otherwise, the only option IS Apple Push not.).
If the app is running you can open an http connection from the app to the server and have the server hold it open, pushing data through it when you want. This is basically how COMET works.
This will only work while your app is running. If you need the notification to happen even if the user has closed the app then Apple Push Notifications are your only option.
You must use Apple Push Notification for achieving push notifications cycle on Apple's mobile devices.

Apple Push Notifications - When Registering for Notifications no Callbacks are received at all

I've gone through all the steps as specified, am using a dev certificate with APN enabled and am calling registerForRemoteNotificationTypes: with the right flags in my app delegate.
Still, neither application:didRegisterForRemoteNotificationsWithDeviceToken: nor application:didFailToRegisterForRemoteNotificationsWithError: are being called. It looks like the registration request just gets stuck in transit.
What am I doing wrong?
This sounds silly, but it's bit me in the past: double-check your capitalization and parameter types. If a delegate method declaration isn't spot on your method won't get called, and you won't get any kind of warning.
Your best bet is to copy and paste the prototype from Apple's documentation.
Try your App on another device. If it works there...
I have the same Problem with one iPhone 3G (no jailbreak, no unlock). It somply dos not work with that phone. I tried updating to a newer iPhone OS. I tried a factory reset. It does show the confirmationscreen and it records the answer in the Settings. But neither application:didFailToRegisterForRemoteNotificationsWithError nor application:didRegisterForRemoteNotificationsWithDeviceToken are ever called.
The same App works on all other tested devices (ipods, iphones). This iPhone 3G does also not receive PNs for other apps.
PNs also did not work for one Jailbroken Classic iPhone.
It might be that your device is simply not behaving correctly. Try a different device.
I had this problem too and it was because of bad certificates, app id, provision profile...
Make sure that:
1, Correct certificates are installed on client AND server
2, Make sure that you have selected correct provision profile in your project settings. REMEMBER App ID in your provision profile has to be specific(not ending with *) and last part of this App ID has to match name of your application exactly and it is case sensitive. so iv your app is called myApp then your app id has to be SOMENUMBERScom.yourcompany.myApp
Just an idea...
I had the same problem and solved it by disconnecting from the cellular network. Seems to be some problem when both wireless and 3G are on concurrently.
I found out that PUSH notifications require port 5223 open in your network (if you are using WIFI), or otherwise, a cellular data connection.
I encountered the same problem in my home network, and had to open the port manually in the wireless router.