Programmatically notification on apple watch. (WatchOS 3) - swift

How I can programmatically make the notification appear only on the apple watch and only when the event occurs. I searched for a long time on the Internet and in the documentation but did not find the answer

There is no way for you to decide whether the notification appears on the Watch or on the Phone, the system handles this automatically and you cannot change this behaviour.
The notification only appears on the Watch if all of the below requirements are met:
The connected iPhone's screen is locked
The watch is worn by the user in case WristDetection is turned on
Do not disturb mode is turned off on the Watch

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 do i start a watch kit notification?

Im creating a app and i would like know how to start a notification to apple watch from apple watch and from iphone to apple watch
I thought local and remote notification could anyone help me????
Do you mean notifications to test your app? Or notifications in general? For notifications in general, I think (but I'm not 100% sure tough) that right now you can't choose where a notification appears, and that both local and remote notifications received by the containing iPhone app will be displayed by Apple Watch (and you can customise their behaviour and style).
To test notifications on Apple Watch, edit the scheme of your watch app and choose to display a notification from a .apns file.
Notification (local or remote) will be appeared on your Apple Watch device as it is paired with your iPhone, iPhone is locked and watches are on your wrist.
To handle incoming notifications on your WatchKit App you should create a Notification Interface Controller in your WatchKit App target's storyboard.
First it will be as a static interface. Also you can add the dynamic one and create a subclass of WKUserNotificationInterfaceController in WatchKit Extension. Link this subclass with the storyboard dynamic notification controller in Identity Inspector pane.
After all you should implement next methods in your subclass:
- (void)didReceiveLocalNotification:withCompletion:
- (void)didReceiveRemoteNotification:withCompletion:
Hope it helps!
in completion with x401om awnser :
you can't fire a local notification from apple watch to iPhone. in fact you can't choose to :
Senario 1 : The user have the phone non-locked, the notification (local or push) is always delivered to the iphone, and not the watch
Senario 2 : The iphone is locked and watch is on you're watch, and you have done some local or push notification (for local at an date and time) then the apple watch recieve the notification.

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.

iOS: Check if the Phone is Locked

Is there a way to check if the phone is locked? Or do I receive a notification of the phone is going to be locked?
My app runs in the background, continues to play audio, so applicationWillResignActive: isn't really what I am looking for.
Checkout UIApplicationProtectedDataWillBecomeUnavailable. This appears to be called when the device is locked. iOS4 + only.
UIApplicationProtectedDataWillBecomeUnavailable
http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html
You can't, directly. Indirectly, you can watch for accelerometer on/off notifications.
Why do you want to detect this event in the first place?

iPhone/iPod Touch sync notifications

I know that it's possible to add an observer for notifications with the com.apple.iTunes.playerInfo identifier, but this only seems to include events for music related events.
I also know I can find out when iTunes closes by adding an observer for NSWorkspaceDidTerminateApplicationNotification.
But is there an NSNotification for the start/finish of iPhone syncing with iTunes?
Just to be clear, my question is about what happens on a Mac not on an iPhone.