Guides
Guides

iOS: Apple Watch

Supporting Apple Watch

Supporting Notifications

By default, all notifications from your iOS device will appear on your watch. This means there is nothing for developers to do in order to "support" Apple Watch.

Customizing The Notification Interface

There are two types of customizations possible when it comes to notifications; custom and dynamic. To start, click your project and go to File > New > Target and select Apple watch. Be sure to tick "Include Notification Scene". Alternatively, you can add one to your existing watch app's storyboard by dragging in a NotificationController object, creating files and linking them up in the identity inspector.

Static Custom Notification Interfaces

This is the most basic type of customization you can do for your alert. For this, you can include static items such as text or images. This will mean that every alert you receive, this content will show. Content can be added directly in Interface Builder. This can be useful if you want to include some help text or branding in your alert. However, a dynamic interface will harness the true power of Apple Watch.

Dynamic Custom Notification Interfaces

In this type of interface, you can have the same text and image outlets as before, but now they can be populated via the content of a push payload from APNS. You can send content for extra text fields and images for display. You have the option to create actions (just like those from interactive notifications in iOS 8) also.

To push custom APNS payloads in Marigold push notifications, simply use the existing Key-Value Payloads feature.

Deep Linking from Apple Watch to iOS

To create a deep link such as a button that says "Read Message" from the alert, which takes the user to their Marigold Message Stream, you need to combine two technologies; Interactive Notifications and Handoff.

Overriding Push Notification Registration

Marigold automatically registers for authorization to display push notifications. To disable this, simply alter your startEngine method:

[[Marigold new] startEngine:@"Your_App_Key" withAuthorizationOption:MARPushAuthorizationOptionNoRequest error:NSError];
Marigold().startEngine("Your_App_Key", with: .noRequest, error: NSError)

From here, you can register your own push notification settings. Settings include alert types (sounds, banners, alerts) as well as a category. With Interactive Notifications, you can declare a category of Notification types when registering for Notifications that include a "Read Message" action. An example is here.

Using Handoff

Inside - (void)didReceiveRemoteNotification:(NSDictionary *)remoteNotification withCompletion:(void (^)(WKUserNotificationInterfaceType))completionHandler you then create a handoff action to interact with the WatchKit app's host app.

NSUserActivity *userActivity = [[NSUserActivity alloc] initWithActivityType:@"com.myapp.ExampleApp.openstream"];
[self updateUserActivityState:userActivity];
let userActivity = NSUserActivity(activityType: "com.myapp.ExampleApp.openstream")
self.updateUserActivityState(userActivity)

In your AppDelegate, implement continueUserActivity.

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *restorableObjects))restorationHandler {
		if ([userActity.activityType isEqualToString:@"com.myapp.ExampleApp.openstream]) {
			//Handle opening the stream, or any deep links you wish to open.
		}
	}
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {    
    if userActivity.activityType == "com.myapp.ExampleApp.openstream" {
      //Handle opening the stream, or any deep links you wish to open.
    }
}

Apple Watch promises some exciting engagement opportunities for your users – be sure to follow the Human Interface Guidelines for Apple Watch to ensure a smooth and captivating experience.