How to create notification groups OneSignal - ios

In my app I've got buttons where if the user presses it they are then 'subscribed' to that channel and will receive notifications for that and which ever other ones they subscribe to. I wanted to know how to do this with OneSignal you can create user segments and send notifications to only those specific groups. So if I create a segment in OneSignal how can I register users to that segment and remove them?
Xcode, swift 3, iOS 10

Use Tags. (from FrontEnd or API)
Example using Frontend:
window.plugins.OneSignal.sendTags({key: "value", key2: "value2"});
Example using API:
URL:
https://onesignal.com/api/v1/players/PLAYER_ID
METHOD:
PUT
HEADERS:
ContentType: application/json
BODY (json):
{
"app_id": "APP_ID",
"tags": {
"key1": "value1",
"key2": "value2",
}
}

Related

Getting silent notification values when app starts

I am trying to implement cache meachanism for FCM on IOS. I am using Xamarin Forms with CrossGeeks FirebasePushNotificationPlugin
Push notification service works fine. I am using payload pattern as below
{
"data": {
"message" : "my_custom_value",
"other_key" : true,
"body":"test"
},
"notification": {
"body" : "hello",
"title": "firebase",
"sound": "default",
"content_available" : true
},
"priority": "high",
"condition": "'general' in topics"
}
Above pattern appears delivered notification as alert on IOS main screen.
I have written a Dependency Service for getting undeleted or unopened accumulated notifications when app starts. Dependency Service include below codes
await UNUserNotificationCenter.Current.GetDeliveredNotificationsAsync();
When I use above payload, I can get accumulated notifications. But when I use payload pattern as below, I can not.
{
"data": {
"message" : "my_custom_value",
"other_key" : true,
"body":"test"
},
"notification": {
"content_available" : true
},
"priority": "high",
"condition": "'general' in topics"
}
Actually I would like to send 2 payload types for every notification for my cache mechanism because of prevent the user's delete action. After that, I would like to show cached notifications without any lost in my app's notification page.
Shortly my question about "I am not getting silent payload values from UNUserNotificationCenter this approach is possible or not?"
Or can I prevent the user's notification delete action from IOS main screen when my app is terminated.
Note: My minimum OS version is 10.0 in info.plist
Thank you in advance.

Firebase not displaying rich push notification

I am using firebase notification in my application. I want to send rich notification but firebase console don't have UI for same. So I am trying to send the payload using postman.
I have created Notification Service Extension for handling content but it never gets called.
Deployment target in xCode is iOS 10.0 and iPad has iOS 11
Json payload(Not Working):
{
"to":"/topics/dev_news",
"mutable_content": true,
"data":
{
"attachment-url":"my image url",
"media_type":"image"
}
}
FYI:
I am able to receive push if I add "notification" key-value in payload.
Json payload(Working but without media):
{
"to":"/topics/dev_news",
"mutable_content": true,
"data":
{
"attachment-url":"my image url",
"media_type":"image"
},
"notification" : {
"title" : "demo push",
"body" : "this is push body"
}
}
Any idea about this??
Answering to my own question, I was searching for attachment-url in data dictionary (which I was passing in the payload) in service extension class. But attachment-url comes directly in the content.userInfo (It is not wrapped inside the data dictionary) in extension class.
Wondering how I can make such a silly mistake..!! :D

apns-collapse-id not merging multiple notifications iOS 10

I am trying to collapse/merge multiple notifications belonging to same event in my app. iOS 10 introduced a key name apns-collapse-id in payload. Document says multiple remote notifications with same apns-collapse-id will merged and shown as single notification.
So we have the payload with apns-collapse-id and thread-id in our notification payload. Unfortunately as there is no much content online explaining how these keys actually works, for safe play we have used the same unique value for both apns-collapse-id and thread-id.
We are expecting the multiple remote notifications with same apns-collapse-id to merge. It is not happenning.
Few people suggested APNS collapse does not come for free and I have to implement UNNotificationContentExtension and handle the notifications manually. I know I can add and remove local notification already posted but not really sure how to update the already posted remote notification.
Here is how our payload looks like
payload {
"aps": {
"alert": {
"title": "Some title : ",
"body": "Some body text"
},
"sound": "default",
"payload": {
"target": {
"some key" : "Some value"
},
"thread_id": "Some_string_155863",
},
"apns-collapse-id": "Some_string_155863",
"mutable-content": 1,
"thread-id": "Some_string_155863",
"badge": 33
},
"thread-id": "Some_string_155863",
"apns-collapse-id": "Some_string_155863",
"mutable-content": 1
}
as you can see apns-collapse-id and thread-id are repeated multiple times in JSON because we aren't sure where exactly to have them
We are not using HTTPS/2 yet, but I believe iOS 10 notfication still supports legacy HTTPS. I am not really a network guy so I don't understand these things completely. Ignore my arrogance towards Https and Http2
Has anybody managed to get apns-collapse-id to work ? Please help.
apns-collapse-id is a request header, so you need to use the HTTP service and not the legacy binary interface.

OneSignal push notification to all segments

I am trying to send push notification from the admin device, to all devices (segment:"ALL"). I can't seem to get it to work with this code.
let data = [
"contents": ["en": "\(message)"],
"included_segments": ["All"],
"excluded_segments": ["None"],
"ios_badgeType": "Increase",
"ios_badgeCount": 1
]
OneSignal.defaultClient().postNotification(data)
The "None" segment exists and has 0 users in it.
"All" has all active users.
When I post the notification I get an error
ERROR: Create notification failed
while this does work without any problems:
let data = [
"contents": ["en": "\(message)"],
"include_player_ids":["20a32b7a-4254-4e03-a24c-13fe8bd91fff"],
"ios_badgeType": "Increase",
"ios_badgeCount": 1
]
OneSignal.defaultClient().postNotification(data)
You can only use include_player_ids from postNotification as other targeting parameters like included_segments require your OneSignal App REST API key.
If you need to target all users you should first make a call to your server from your app where you can safely use the create notification REST API POST call.

Sending Parse push notifications to multiple applications from single application

I am wondering if it is possible to send push notifications to different IOS applications from only one IOS application via Parse.com API. I can already send a push notification in same application but I want to send to different applications of mine, from a single application.
You can technically use the REST API from Cloud Code, calling back in to Parse with different headers.
Parse.Cloud.httpRequest({
method: "POST",
headers: {
"X-Parse-Application-Id": YOUR_APP_ID,
"X-Parse-REST-API-Key": REST_API_KEY,
"Content-Type": "application/json"
},
body: {
"data": {
"alert": "Yo"
}
},
url: "https://api.parse.com/1/push"
}).then(function() {
console.log("Successful push");
}, function(error) {
console.log(error);
});
Taken from official forums here: Click here

Resources