didrecieveremotenotification(:) delegate method - ios

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

Related

FCM PUSH NOTIFICATION WITH IMAGE:- how to display tile, description and image in fcm push notification in ios swift

how to display tile, description and image in fcm push notification in ios swift.
I extend NotificationViewController and NotificationService but NotificationService never calls.
Here is notification payload in the foreground.
For Good Suggestion. Thank in advance
PayLoad
{
"alert": {
"body": "Message",
"title": "appname"
},
"content-available": 1,
"mutable-content": 1,
"sound": 1
}

iOS 10 FireBase when notification arrived, do not get call NotificationService.h Notification Service Extension

I use firebase and get successfully Notifications but when notification arrived, do not get call NotificationService.h Notification Service Extension.
I also set
NSExtensionPrincipalClass to NotificationService
NSExtensionPointIdentifier to com.apple.usernotifications.service
My notification is like
{
"registration_ids": ["devicetoken"],
"mutable_content": true,
"data":{
"post_details": {
"pcm_message": "asdf",
"pcm_img_url": "http://portalvhds34w6bf5z9b21h.blob.core.windows.net/images/1519365008_5a8fab90cf683.jpg",
}
},
"notification" : {
"title" : "demo push",
"body" : "this is push body" }
}
where is a problem or missing some information I have already set deployment target 10.0 in my whole project.

IOS Access Push notification payload before user gets push notif

I'm trying to access the push notification payload before user actually gets the push notification. I want to create some sort of filter of the push notifications that the user receives. Is this possible?
You can get notification payload before it fired using this extension "NotificationService"
Add one target in the project and you can get notification data in bellow function.
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
}
One more thing you need to add is in notification payload add two-parameter like this
{
"aps":{
"alert": {
"title": "This it title",
"body": "This is body"
},
"mutable-content":1,
"content-available":1
},
"mediaType": "png",
"mediaUrl": "your url her"
}
"mutable-content":1,
"content-available":1
mutable content and content available = 1
if you do not add these two keys in payload then the above function should not call.
Thank you.

Apple watch real response data

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."
}

How we can fetch push notification in background

I am receiving push notification in that payload message i am receiving one URL with message as push notification. but i dont want to show URL to user i want to show only message to user. is it possible from ios side.
If your are using url as a separate key in aps then its possible you can display alert only as a message, otherwise any message can't be modify message in background.
"aps": {
"alert": "alert!",
"sound": "default",
"URL" : "your url"
}
yes, its possible but it also depend on how you have created your payload but its simple as you create your payload with your link and message, receive at your delegate
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)pushChatObject {
// get the message value and NSLog is or set to UIAlert or in NSString
(pushChatObject)[#"Message"];
}
You can, but you shouldn't, because
Delivery of notifications is a “best effort”, not guaranteed. It is
not intended to deliver data to your app, only to notify the user that
there is new data available.
(c) Apple
Specify the notification message as
{
"aps": {
"alert": "alert!",
"sound": "default"
},
"URL": "http://apple.com"
}
When you receive the notification in the app just check for your param in the notification dictionary:
// Place this method to AppDelegate.m
- (void)application:(UIApplication *)application didReceiveRemoteNotification:
(NSDictionary *)notification {
if ([notification objectForKey:#"URL"]) {
NSString *url = [[notification objectForKey:#"URL"] stringValue];
}
}
Check this section of Apple's Local and Push Notification Programming Guide for more info
I think in this case you can use Child properties of the alert property, you use 1 argument as a alert and another argument as a url, like:
"aps": {
"alert" : {
"loc-key" : "ALERT",
"loc-args" : [ "Your alert message", "Your url"]
},
"sound": "default"
}
When the device receives the notification, it uses "ALERT" as a key to look up the associated string value in the Localizable.strings file in the .lproj directory for the current language. Assuming the current localization has an Localizable.strings entry such as this: "ALERT" = "%#";
And later on you can get your url using aps NSDictionary.

Resources