Display both alertTitle and AlertBody on a custom WatchKit notification

783 views Asked by At

When I send a local notification to the Apple Watch with both an alertTitle and an alertBody, both fields get displayed on the long look notification. But when I customize this with a Static Notification Controller Interface Scene, the default storyboard in XCode only has one field, which gets populated with the alertBody (not the alertTitle).

How can I configure the storyboard to include both fields? I can add a new label to the storyboard, but I can't figure out how to link the new label to the alertTitle field.

Here's the code I use to present the notification:

var localNotification = UILocalNotification()
localNotification.alertTitle = "Silver Maple"
localNotification.alertBody = "Silver Maple (1658) Acer saccharinum"
UIApplication.sharedApplication().presentLocalNotificationNow(localNotification)

Here's what it looks like without a custom interface:

enter image description here

And here's my storyboard showing the customized interface with only the alertBody showing:

enter image description here

1

There are 1 answers

1
Becky Hansmeyer On BEST ANSWER

In the Apple Watch Programming Guide: Managing a Custom Long-Look Interface (under the section "Configuring a Static Notification Interface," it says:

The interface’s notificationAlertLabel outlet must be connected to a label. The label’s contents are set to the notification’s alert message. The text for all other labels does not change.

Unfortunately, I don't think it's possible to link your custom label to the alertTitle field. If you look at the Static Interface controller in Interface Builder, you'll notice it's not in any way linked to your custom WKUserNotificationInterfaceController class. Therefore, there's no way to actually hook up any outlets manually.