Apple Watch notification error "Unhandled Category" - ios

I'm working with Apple Watch Notifications.
I defined my own category "myAppcategory" and passed the same to notification payload.
But, still i'm receiving below warning in XCode.
Warning: Notification category "(null)" not found. Define this category or a default category in your storyboard.
And result in watch simulator is below
Can any one help me to fix this issue?

I recently had the same issue. For me it was an invalid push notification payload. If you're using a .apns file (for example the sample one provided for notification controllers) to test make sure it's formatted correctly.

This issue is most probably is caused after a mistaken edit that broke the formatting on the PushNotificationPayload.apns file. To resolve this issue fix the formatting in your .apns file.
The most problematic part is when you add data to alert. Make sure you add comma after each entry, except last one.
"alert": {
"body": "Test message",
"title": "Optional title",
"name": "MyName"
},
Like this.

Try to remove application from iphone simulator. I had the same error and I've resolved it in this way

Also, watch for the comma in the button list
"WatchKit Simulator Actions": [
{
"title": "Stop/Save Activity",
"identifier": "stopsave"
}, // <===== THIS ONE HERE
{
"title": "Cancel Activity",
"identifier": "cancel"
}
],

You should add category value in your payload and define it in your storyboard.
"aps": {
"alert": "Test message",
"sound": "Optional title",
"category":"myCategory"
}
reference: https://developer.apple.com/library/ios/documentation/General/Conceptual/WatchKitProgrammingGuide/CustomzingthePushNotificationInterface.html

Related

how to add image to iOS firebase remote notification

the scenario that I am trying to achieve is that when the iOS app is closed, the remote firebase notification with an image should popup,the image can be in place of the app logo or a bigger image can open on user tap.
I am successfully getting the notification but I dont know how to add an image into it.I am guessing I"ll have to override the UNUserNotificationCenterfunctionalities and add something to the payload like
{
"priority":"high",
"notification": {
"title": "Portugal vs. Denmark",
"body": "5 to 1",
"icon": "my desired image"
},
"to": "ebBUO1R..."
}
I'd be glad if anyone can point me towards the right direction or any help(preferably in swift).
Regards

Multi line title in push notification for iOS

I'm integrating FCM for an app which has both iOS and Android version.
Currently, for iOS, I want to send title in multiple lines. How do I do this? I'm trying out using Firebase console to test. But nothing seems to work for me.
I tried with these
\n
<br/>
\\n
\r\n
as suggested in this post. But nothing really worked.
I basically want the first 2 lines of the notification to be in bold. Any help much appreciated.
The 1st line in bold you see is a notification Title, the second the Subtitle, and the Content underneath (regular font).
These are properties of a notification, since iOS 10 set on UN(Mutable)NotificationContent (subtitle line is not available before).
They properties can be configured in the payload sent via APNS:
{
"aps": {
"alert": {
"title": "Custom title",
"subtitle": "Custom subtitle",
"body": "Custom message"
}
}
}
Also, you can create a UserNotificationServiceExtension to update the above properties of a notification that has been received.

Payload for the Watch App Notification

When creating a new Apple Watch App in Xcode, the following APNS payload example is created:
{
"aps": {
"alert": {
"body": "Test message",
"title": "Optional title"
},
"category": "myCategory"
},
"WatchKit Simulator Actions": [
{
"title": "First Button",
"identifier": "firstButtonAction"
}
],
"customKey": "Use this file to define a testing payload for your notifications. The aps dictionary specifies the category, alert text and title. The WatchKit Simulator Actions array can provide info for one or more action buttons in addition to the standard Dismiss button. Any other top level keys are custom payload. If you have multiple such JSON files in your project, you'll be able to select them when choosing to debug the notification interface of your Watch App." }
I am confused by the use of body and title within the alert dictionary. The following payload is ordinarily used in iOS apps:
{
"aps": {
"alert": "Test message",
"title": "Opt title",
"category": "default"
},
"WatchKit Simulator Actions": [
{
"title": "First Button",
"identifier": "firstButtonAction"
}
],
"customKey": "Use this file to define a testing payload for your notifications. The aps dictionary specifies the category, alert text and title. The WatchKit Simulator Actions array can provide info for one or more action buttons in addition to the standard Dismiss button. Any other top level keys are custom payload. If you have multiple such JSON files in your project, you'll be able to select them when choosing to debug the notification interface of your Watch App."
}
Which is the correct way? Although a default payload file is created in this way, the Apple documentation provides a screenshot using the latter variant.
In the Local and Remote Notification Programming Guide(Table 3-1), the value type of alert key can be string or dictionary, as Dhawal said, both formats are correct.
If alert is dictionary, it can contain title, body, title-loc-key etc(Table 3-2). What's the purpose of title key? This key was added in iOS 8.2 which contain WatchKit, and WatchKit has a Short-Look Notification interface, there is no enough space for full notification, so Apple Watch use title to describe the purpose of the notification and display in Short-Look Notification.
(source: edgekey.net)
In this picture, "Gray's Birthday" is the title in alert. Because you can't see Short-Look Notification in simulator, you should test result of title key in REAL Apple Watch.
Based on the Apple documentation, here is the following keys that you can have in the aps dictionary: alert, badge, sound and content-available. And here is keys that you can have in the alert dictionary: title, body, title-loc-args etc. You can check it the Push Notification Programming Guide for more information here:
Push Notification Programming Guide
Check this as well for your WatchKit Extension, Apple Watch Programming Guide
Also, the second way you describe should be the correct way. I just create a Watch App and it includes the sample payload. And the category is put inside the aps outside the alert which should be incorrect in this case. Hope this helps. It means that aps can only contain those four default properties. So, category should be contained inside the alert.
Apple Documentation for Push Notification Payload has mentioned a Note,
Note: If you want the device to display the message text as-is in an
alert that has both the Close and View buttons, then specify a string
as the direct value of alert. Don’t specify a dictionary as the value
of alert if the dictionary only has the body property.
So as per above note, both formats are correct but we should use second format (alert with directly text value instead of dictionary) when you only need body property in Alert. If you need to use other child properties of Alert like body, title,...then you should use first format (Alert with dictionary as value).

WatchKit Notification payload example

As you may know, on the PushNotificationPayload.aps file, actions can be set on the "WatchKit Simulator Actions" node.
Can someone provide me a real push notification payload that includes actions?
Thanks!
We use a test payload that looks something like this:
{
"aps": {
"alert": {
"title": "My Alert Title",
"body": "The body message",
},
"category": "myCategoryName"
},
"WatchKit Simulator Actions": [
{
"title": "Like it!",
"identifier": "MY_LIKE_ACTION"
}
],
"myCategoryDictionary": {
"image" : "http://.....",
"subject" : "The subject of the alert message",
"content": "Detailed content info can go here"
},
"customKey": "Use this file to define a testing payload for your notifications. The aps dictionary specifies the category, alert text and title. The WatchKit Simulator Actions array can provide info for one or more action buttons in addition to the standard Dismiss button. Any other top level keys are custom payload. If you have multiple such JSON files in your project, you'll be able to select them when choosing to debug the notification interface of your Watch App."
}

Is the following structure with body and loc-args in the same notification payload valid?

Would the following payload notification cause any problems if you have body and loc-args and loc-key in the same payload?
{"aps":{"alert":{"body" : "Bob wants to play poker", "loc-key":"general","loc-args":["Test DEFAULT."]},"badge":1,"sound":"default"}}
The reason I have it set up like this. Is that I am not sure if the notification to just have a body in would be handle during the app, so it would use the localized loc-args in with the following key-valus in the localizable string:
"general"="%#";
I've made several tests.
For example sending
{
"aps": {
"alert": {
"body": "hello world!",
"loc-args": ["andy", "my text"],
"loc-key": "comment"
}
},
"sound": "default",
"extras": {}
}
On my device I have a string in the loc file that looks like:
"comment" = "%# has comment %#";
So the notification that I'm receiving is:
Andy has comment my text
Now I've sent a new notification like this:
{
"aps": {
"alert": {
"body": "hello world!",
"loc-args": ["andy", "my text"],
"loc-key": "does_not_exist"
}
},
"sound": "default",
"extras": {}
}
with a loc-key that does not exist, and the notification that I'm receiving is
does_not_exist
so as kadam said in his answer:
Ultimately, one can infer from the docs that body and loc-key should
be used in an exclusive or relationship. Either one or the other, but
not both.
Blockquote
According to this post, if the key is missing the key is used. That's why 'body' is always ignored and is EITHER ONE or the OTHER.
There are two options to localize an alert message embedded in a push notification. One is to localize on the server and send the localized message as a string value of the alert key. Eg:
{"alert": "A localized sentence."}
Optionally, if you want to also set the launch image and/or have the view button of the alert read something other than 'View', you would replace the string value of alert with a dictionary. In this case the string value should be the value of body in the dictionary. Eg:
{'alert':
{'body: "A localized sentence.", action-loc-key: "...", launch-image: "..."'
}}
The docs warn that if you only have the body key in the dictionary, don't use a dictionary. Instead set the value of body as the string value of alert.
The other option is to use the loc-key, loc-args pair and have the localization take place on the device.
Although I have not verified which one iOS defaults to if both body and loc-key are present in the alert dictionary, I guess it will pick one and ignore the other. Someone with access to a working push notification dev setup could verify which one.
Ultimately, one can infer from the docs that body and loc-key should be used in an exclusive or relationship. Either one or the other, but not both.
I'm not 50 yet so I can't comment but to follow-up on #kadam answer, just for future reference to those who will visit this question.
Although I have not verified which one iOS defaults to if both body and loc-key are present in the alert dictionary, I guess it will pick one and ignore the other. Someone with access to a working push notification dev setup could verify which one.
I have tried it and it defaults to the value of loc-key if it has a value on the app itself. If none then it uses the value of body.

Resources