Show a notification from watchOS 2 app - swift

It is possible to show a notification from Apple watchOS 2 native app? Although watchOS 2 applications can run directly on the Apple watch device, it still hasn't reference to the UIApplication.SharedApplication, so I can't all the UIApplication.presentLocalNotificationNow() directly from the WatchKit app an it seems that also the WKExtensionDelegate cannot be used to show instant notifications.

The WKExtensionDelegate can respond to local notifications via the didReceiveLocalNotification(_:) method. Your iPhone app will have to schedule the notification. If it is an even that only the watch knows about, you can send a message to the phone app using the WCSession set of APIs.

Related

WCSession counterpart app not installed or installed throughout settings in the watch app

I have developed my watch app for my iOS App. The problem is that I need to use WCSession logic in order to send data from iOS to the AppWatch and vice versa.
If I install from Xcode, I get "WCSession counterpart app not installed" error message, so I wanted to install it throughout the settings view in the watch app but it does NOT appear here.
So how can I get my watch App appears there?

IOS & WatchOS background communication

I have a IOS application with a companion WatchOS application. I am wondering if there is a way I can communicate with the IOS application in real time while it not running as a foreground application.
The best example I can think of is how your are able to use the Spotify watch app to change songs, like songs or even change the volume of the phone while the phone is locked.
How could I implement something like this for an application that could possibly send data frequently from the watch to the phone while the phone is locked.
Watch apps can launch their companion iOS apps by messaging them:. https://developer.apple.com/documentation/watchconnectivity/wcsession/1615687-sendmessage
That won’t work if the iOS device requires unlock because it’s just booted up.
I just started WatchOS development and needed to send a message to the watch app - if it's available I use sendMessage. If the watch app is backgrounded, I use transferUserInfo. Link to code snippets. I check isReachable and isPaired (on the phone, isPaired does not exist in WatchOS).

Something like shared NSUserDefaults and App Groups in watchOS 2?

I am currently updating an app of mine for watchOS 2 and got some trouble with communication between the devices: previously I had been using shared NSUserDefaults to enable both the Watch and the iOS device to read and write several values from one App Group independently.
Now that watchOS 2 apps are running natively on the Watch and the Watch Connectivity Framework replaced previous communication options, this no longer seems applicable. However, from what I read on the reference, implementing the same functionality I had in watchOS 1 with Watch Connectivity is rather cumbersome…
Is there any other option for me to create some sort of container/file/database/whatsoever that I can access and update from both my Watch app and the related iOS app?
With watchOS 2 both the WatchKit App and Extension run natively on Apple Watch, so even if you use shared user defaults or app groups the data you put inside them will be on the watch and so not accessible from the iOS app.
To send data to the watch you can use the WatchConnectivity framework, or use a NSURLSession to download data from a server if that's your case.

How to test push notification on the Apple watch?

I'm able to test push notification using Apple Watch simulator and the "PushNotificationPayload.apns" file by selecting Notification:
How to test push notification on the actual Apple Watch?
--> I've tried to use exact steps for simulator. But the Apple Watch will just launch the app, bypassing the notification view.
The APNS file is available only for testing in the simulator. It doesn't work on a real device. You'll have to test push notifications the same way you would for an iOS app: actually sending a push notification to the device.
There is a simple process to test the push notification on Apple Watch. It is same as in iPhone. Also Inside your iPhone -> Apple Watch-> Notifications -> Mirror iPHONE alerts From-> turn on your notification.
There are following things which you need to take care while testing the Push notification on Watch:-
1) IPhone should not be active and Watch should be active.
2) IPhone and watch both should not be active.
3) IPhone and watch both should not be deactive.

How to send msg between iPhone app and WatchKit app?

I am newer one for Apple Watch development.
Can you please provide me about how to communicate from iPhone app to Watch app and from Watch app to iPhone app ?
As I can see, there is a notification controller which is related Apple Push notification. I would like to connect to Watch app directly via Bluetooth or something. For example, As soon as iPhone app sends a MGS to Watch app, the watch app shows this MSG without any delay.
Thank you.
In order to communicate with the iPhone app from your Watch extension you can use openParentApplication(_:reply:) since Beta 2.
For the other way around I have been putting a file into the shared app group folder and monitor it from the Watch extension. If the iPhone app modifies the file the Watch extension will be notified and can act on it.