Hi I develop on iOS and follow through this instruction
https://www.avanderlee.com/swift/rich-notifications/
and my "notification.apns" look like this
{
"Simulator Target Bundle": "com.xxxxxxxxxxxxxxxxx",
"aps": {
"category": "content_added_notification",
"alert": {
"title": "Photos",
"body": "Antoine added something new - take a look"
},
"mutable-content": 1
},
"image_url": "https://upload.wikimedia.org/wikipedia/commons/d/d5/Basketball_Ball_Icon.png"
}
And notification show like this.
What wrong with it??
Just reboot your device. It's another bug of new release I suppose
Related
I have created .apns file for push notification and I am getting push notification on iOS simulator but when I am trying to call didrecieveremotenotification(:) delegate method nothing printed. My .apns file looks like this:
{
"aps": {
"alert": {
"title": "Push notification",
"body": "This is push notification demo",
"sound": "default"
},
"content-available": 1
},
"Simulator Target Bundle": "bundle identifier"
}
Are you calling explicitly didrecieveremotenotification(:) delegate method? basically this delegate will be called by the system when it receives notifications. For more info you can refer: https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623013-application
I have an issue with Notification Service Extension on iOS 13. This issue is not always happen.
When I push a notification with mutable-content = 1, on development apple server ( api.sandbox.push.apple.com:443), Apple return success on my server, but no notification comes to my device. Sometimes it still comes, but very late, for example I push it at 9:00 AM, it comes to my device at 9:15 AM, and show exactly time (15 mins ago).
Is this an apple error or my error? If it's my error, how do I fix this? And if it's Apple's error, does it happen on real server (api.push.apple.com:443)?
Thanks!
"Mutable-content" should be inside "aps" dictionary
Try this if you are sending from apns server
{
"aps": {
"category": "content_added_notification",
"alert": {
"title": "Photos",
"body": "Antoine added something new - take a look"
},
"mutable-content": 1
},
"image_url": "https://www.example.com/image_url"
}
And this if you are sending from firebase
let dict = ["to": "SERVER-KEY",
"notification":["body":"body text",
"title":"notification text",
"category": "myNotificationCategory",
"mutable-content": true],
"data":[
"mediaUrl": "https://homepages.cae.wisc.edu/~ece533/images/airplane.png"
]]as [String:Any]
I'm trying to display a custom Long-Look UI when receiving a local notification on my watch extension.
I tested this sample .apns payload:
{
"aps": {
"alert": {
"body": "Test message",
"title": "Optional title"
},
"category": "myCategory",
"thread-id":"5280"
},
"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."
}
and it works fine. I also have a dynamic notification scene designed on the storyboard.
I'm scheduling local notifications from the iOS side like this (and lock the phone right afterward to force the notification to go on my watch)
let content = UNMutableNotificationContent()
content.title = "Early bird"
content.categoryIdentifier = "myCategory"
content.userInfo = [
"userData": [
"WatchKit Simulator Actions": [
[
"title": "Button 1",
"identifier": "button1Action",
],
[
"title": "Button 2",
"identifier": "button2Action",
]
]
]
]
I think I'm setting my userInfo wrong. How do I set the correct payload so my watchOS extension can render the long-look correctly?
Can you print and show me the output of this with real device I need to know the format of it.
- (void)didReceiveRemoteNotification:(NSDictionary *)remoteNotification withCompletion:(void (^)(WKUserNotificationInterfaceType))completionHandler
{
// This method is called when a remote notification needs to be presented.
// Implement it if you use a dynamic notification interface.
// Populate your dynamic notification interface as quickly as possible.
// After populating your dynamic notification interface call the completion block.
NSLog(#"%#",remoteNotification);
completionHandler(WKUserNotificationInterfaceTypeCustom);
}
This is the Payload response for the question
{
"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 want to add values to the apple watch notification (the current screen uses hard coded data):
The values I want to add are for these fields: "Amount", "At" and "When". How can I add get this values from the PushNotificationPayload.apns file and show it on the notification?
This is the PushNotificationPayload.apns file:
{
"aps": {
"alert": {
"body": "New Transaction\n\n",
"title": "Optional title"
},
"category": "newTransactionCategory"
},
"WatchKit Simulator Actions": [
{
"title": "Details",
"identifier": "transactionDetailsButtonAction"
}
],
"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."
}
These are the steps,
Create a new class which is a subclass of WKUserNotificationInterfaceController.
From the storyboard, select your Dynamic Interface Scene for notification (if you have not created it, enable 'Has Dynamic Interface' in attribute inspector of your Static Scene ) and in Identity Inspector set custom class as created above.
Now modify your PushNotificationPayload.apns file contents as below,
{
"aps": {
"alert": {
"body": "New Transaction\n\n",
"title": "Optional title"
},
"category": "newTransactionCategory"
},
"WatchKit Simulator Actions": [
{
"title": "Details",
"identifier": "transactionDetailsButtonAction"
}
],
"Amount": "USD 20",
"At": "Mc Donalds",
"When": "Today",
}
When a remote notification is received, this method will be called in your custom notification interface class and you will receive the custom keys in the dictionary 'remoteNotification' which you need to use to set the text of your labels here.
-(void)didReceiveRemoteNotification:(NSDictionary *)remoteNotification withCompletion:(void (^)(WKUserNotificationInterfaceType))completionHandler {
NSLog(#"remoteNotification Dictionary %#",remoteNotification);
completionHandler(WKUserNotificationInterfaceTypeCustom);
}
Last is debugging:
Select your targets on the top and select Edit Scheme
Click on duplicate scheme at the bottom and give your custom name like 'NOTIFICATION-Mywatchkitapp' etc...
Then, select WatchKit Interface to Dynamic Notification, Notification Payload to your PushNotificationPayload.apns file and run for this target.