Hi I want to implement push notifications , I have three devices to test it : Iphones 4, 5s , 6
All of them using IOS 9.3.2 and are registering in my provisioning profile.
The push notifications work just fine in my Iphone 5s and if my app is in active mode, Im getting the following message in the console when receiving push:
%# [aps: {
alert = {
body = "Jonathan : test me ";
title = test;
};
}, gcm.message_id: 0:1470515051789092%8d989dbf8d989dbf]
but when I try to get manage to get push notification in my other device , Im not getting the push in background and when entering my app Im gettting the following message in my console:
%# [from: 199968158838, collapse_key: com.jerem.***********, notification: {
body = "Jerem :test me ";
e = 1;
title = test;
}]
I dont succeed in sending them notifications from the Firebase console too,
thanks for your help!
I had the same problem with iOS 9.3.2, but when I reinstall my app not working on iPhone 5s too. The problem was with token, so I add this method and is's working:
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: .Sandbox)
}
Remember .Sandbox type is for development mode.
Related
I have been looking all over the threads of a way to make the app recieve the silent push notification while the app is terminated.
I have tried:
{
"data" : {
"foo" : boo
},
"apns" : {
"header" :{
'apns-priority' : '10' && i also tried 5
}
"aps" : {
"content-available" : 1
},
}
}
I know it´s possible since ton of apps use it to update app content while app is killed or after mobile restart. When I open the console I can see that the message is arrived but my app doesnt wake up.
I have made a print('xx') right at the beginning of my app.
I have no issue receiving data notifications on background/foreground,
I am working on a project where I want to make Push notifications work, on Parse-Server (Heroku), with an iOS app.
This is the code I use on the server side to generate a PUSH:
const pushQuery = new Parse.Query(Parse.Installation);
pushQuery.equalTo('deviceType', 'ios');
Parse.Push.send({
where: pushQuery, // Set our Installation query
data: {alert: "ABCXYZ"}
}, {
useMasterKey: true,
success: function() {},
error: function(error) {
throw "Got an error " + error.code + " : " + error.message;
}
});
On the iOS app side, I receive the notification, but I would like to tweak it to my taste, if possible.
Here is the relevant swift code where I can see the notification coming:
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: #escaping (UNNotificationPresentationOptions) -> Void) {
print(#function)
print("NN = \(notification.description)")
}
And finally, this is what I can see in the Xcode debugging console, when the notification arrives:
userNotificationCenter(_:willPresent:withCompletionHandler:)
NN = <UNNotification: 0x2....; date: 2020-03-02 06:51:39 +0000,
request: <UNNotificationRequest: 0x28....3e0; identifier: 0C....AF3,
content: <UNNotificationContent: 0x28....6c0; title: (null), subtitle: (null),
body: ABCXYZ, summaryArgument: , summaryArgumentCount: 0, categoryIdentifier: ,
launchImageName: , threadIdentifier: , attachments: (
), badge: (null), sound: (null),,
trigger: <UNPushNotificationTrigger: 0x28...0;
contentAvailable: NO, mutableContent: NO>>>
Obviously, it is working up to a point. But I can see fields in the incoming notification that I do not control. Namely: title, subtitle, summaryArgument, categoryIdentifier ...... In fact only "body" is what I have set on the server side.
Therefore my question is: how can I set all those fields the way I wish.
I have already tried something like this:
data: {
title: "MyOwnTitle",
alert: "ABCXYZ"
}
But without success.
Furthermore, by using something like:
data: {
alert: "ABCXYZ",
content_available: 1,
push_type: "background",
category: "S3x"
}
I can see the following in the Xcode debugging console, when the notification arrives:
userNotificationCenter(_:willPresent:withCompletionHandler:)
NN = <UNNotification: 0x28...; date: 2020-03-03 ...,
request: <UNNotificationRequest: 0x2..;
identifier: BF...EE, content: <UNNotificationContent: 0x28..;
title: (null), subtitle: (null), body: ABCXYZ,
summaryArgument: , summaryArgumentCount: 0,
categoryIdentifier: S3x, launchImageName: ,
threadIdentifier: , attachments: (
), badge: (null), sound: (null),,
trigger: <UNPushNotificationTrigger: 0x28..;
contentAvailable: NO, mutableContent: NO>>>
Where it appears that the "ABCXYZ" part is transferred as well as the category (S3x), but the rest (content_available,push_type) seems to be ignored.
According to Parse push notification docs, you can send the following options in your push notification payload:
alert: the notification’s message.
badge: (iOS only) the value indicated in the top right corner of the app icon. This can be set to a value or to Increment in order to increment the current value by 1.
sound: (iOS only) the name of a sound file in the application bundle.
content-available: (iOS only) If you are a writing an app using the Remote Notification Background Mode introduced in iOS7 (a.k.a. “Background Push”), set this value to 1 to trigger a background download. You also have to set push_type starting iOS 13 and watchOS 6.
push_type: (iOS only) The type of the notification. The value is alert or background. Specify alert when the delivery of your notification displays an alert, plays a sound, or badges your app’s icon. Specify background for silent notifications that do not interact with the user. Defaults to alert if no value is set. Required when delivering notifications to devices running iOS 13 and later, or watchOS 6 and later.
priority: (iOS only) The priority of the notification. Specify 10 to send the notification immediately. Specify 5 to send the notification based on power considerations on the user’s device. (More detailed documentation)
category: (iOS only) the identifier of the UNNotificationCategory for this push notification.
uri: (Android only) an optional field that contains a URI. When the notification is opened, an Activity associated with opening the URI is launched.
title: (Android only) the value displayed in the Android system tray notification.
Besides these, you can also write a custom push notification handler in your iOS app by following this guide: http://docs.parseplatform.org/ios/guide/#responding-to-the-payload
I'm working on call/video application. I'm using SINCH SDK and i successfully integrated in swift project and call video work fine but i have a problem that when user is logged out from application still received a notification, i don't know why i used this function to logout
func logOutSinchUser() {
if let client = self._client {
client.stopListeningOnActiveConnection()
client.terminate()
client.unregisterPushNotificationData()
}
self._client = nil
}
Anyone can help me please ?
Please try to unregister the push token first(unregisterPushNotificationDeviceToken if you use sinch managed push) before you terminate the sinch client.
Also use terminateGracefully instead, to give the SDK more time to handle the unregistration process before shut off.
Could be sth like:
func logOutSinchUser() {
if let client = self._client {
client.stopListeningOnActiveConnection()
client.unregisterPushNotificationDeviceToken()
client.terminateGracefully()
}
self._client = nil
}
Does someone have experience with ionic 1 push notifications? Is there any alternative to cloud solution that they suggest? And can someone show example of implementatio? And please have on mind that I'm completly new in ionic
I use this plugin https://github.com/phonegap/phonegap-plugin-push to handle push notification.
var pushOptions = {
android: {
senderID: "1234567890",
icon: "push_icon",
iconColor: "#FFF"
},
ios: {
alert: true,
badge: true,
sound: true
}
};
var push = PushNotification.init(pushOptions);
push.on('registration', function () {});
push.on('notification', function () {});
After test several push servicies (ionic push service, parse, pushwoosh and one signal) we choose one signal as push notification provider. Right now we use it in 30+ production applications in our company. In 10 minutes or less you can set up an app for first push notification use in android or iOS (platforms we are working right now)
The platform has an easy set up guide.
The only code in app for basic setup is:
$ionicPlatform.ready(function() {
// Enable to debug issues.
// window.plugins.OneSignal.setLogLevel({logLevel: 4, visualLevel: 4});
var notificationOpenedCallback = function(jsonData) {
console.log('notificationOpenedCallback: ' + JSON.stringify(jsonData));
};
window.plugins.OneSignal
.startInit("YOUR_APPID")
.handleNotificationOpened(notificationOpenedCallback)
.endInit();
// Call syncHashedEmail anywhere in your app if you have the user's email.
// This improves the effectiveness of OneSignal's "best-time" notification scheduling feature.
// window.plugins.OneSignal.syncHashedEmail(userEmail);
})
Just modify "YOUR_APPID" by yours and thats all.
Follow de docs above for make it works in your desired platform.
Check out OneSignal. It's free, easy to use and multi-platform Push Notification framework.
I have iOS app written in Swift. I use Parse SDK for push notifications.
I want to add badge to app icon when push is received. There is problem - I can't add badge from push directly because there are a lot of users that use previous version of my app. And if I add badge from push - this badge will not disappear because previous app versions don't hide badge after it opened. So badge will be always on icon.
So what I want is to handle push by my app. No matter is it running or not. If push arrives - my app adds badge. So I can I handle push by my app if it is not running?
I know how to add badge with Swift
application.applicationIconBadgeNumber = 5
But how can i do it without opening the app - just when push is received?
When you push the app, you need to send the badge count with it:
{
"aps": {
"alert": "message goes here",
"sound": "sound.aiff",
"badge": 5
}
}
This will change the badge number on the app before it has been opened.
Please note that you cannot change the badge number of an app when it is closed without using notifications to do so.
Like said in the Parse docs, you can set badge number setting the badge field in the payload with an integer
ex:
"data": {
"alert": "The Mets scored! The game is now tied 1-1.",
"badge": 5,
"sound": "default",
"title": "Mets Score!"
}
or with Increment to automatically increment current value in badge count
ex:
"data": {
"alert": "The Mets scored! The game is now tied 1-1.",
"badge": "Increment",
"sound": "default",
"title": "Mets Score!"
}
To send push notifications with Parse just use the following code, making sure you change the channel to the correct one:
let push = PFPush()
push.setChannel("MyChannel")
push.sendPushInBackground()
Then to hide the badges once the user opens the app back up, add the following function to your AppDelegate.swift:
func applicationDidBecomeActive(application: UIApplication) {
//Reset badge counter to zero
var currentInstallation = PFInstallation.currentInstallation()
if(currentInstallation.badge != 0){
currentInstallation.badge = 0
}
}
since Parse SDK keeps it's own badge count separate from iOS app badge count, you need to follow it like this to rest the badge count to zero.
- (void)applicationDidBecomeActive:(UIApplication *)application {
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
if (currentInstallation.badge != 0) {
currentInstallation.badge = 0;
[currentInstallation saveEventually];
}
// ...
}
In Swift 2.0,
let parseinst: PFInstallation = PFInstallation.currentInstallation();
if (parseinst.badge != 0)
{
parseinst.badge = 0;
parseinst.saveEventually()
}