Push notifications for apple in phonegap - iphone

I am implementing an iphone app using phonegap. I use urban airship for push notifications. The push notifications work well, the only bug is that the title of the notifications is "index.html". Does someone know how to change this default title?

Instead of just using standard alert(), use the alert function from the Phonegap API:
navigator.notification.alert(message, alertCallback, [title], [buttonName])
In your case it would be something like:
navigator.notification.alert(theAlertMsgVar, null, 'Your title', null);

Related

Ionic 3 Notification

I want to use notification with my app. I have checked ionic native and find some information.
First;
Local Notification
Second;
Push
What do I want to do? I am using MySQL Database and I have two tables users and points. When I add points for one user, I want to send notification for only this user. How can I do this? Which can I use service?
As per your required I suggest you to use Push Notifications using FCM.
push notifications help to send notification into two or more ionic apps.
please follow these steps.
go to 'http://console.firebase.google.com' and create an android app make sure that app package name also mention in config.xml file.
Install the Cordova and Ionic Native plugins in App:
ionic cordova plugin add cordova-plugin-fcm
npm install --save #ionic-native/fcm
use this code in your 'app.component.ts' file with in initializeApp
/getToken generates a device token that helps you to send notification on this device.you have to store this token in your database when app is open./
fcm.getToken().then(token=>{
console.log(token);
});
fcm.onNotification().subscribe(data=>{
if(data.wasTapped){
console.log("Received in background");
} else {
console.log("Received in foreground");
};
});
fcm.onTokenRefresh().subscribe(token=>{
console.log(token);
});
Now the real process that you have to follow for send notification
/here is you have to add device token that is you have store in your database and your firebase api key./
let body = {
"notification":{
"title":"New Notification has arrived",
"body":"Notification Body",
"sound":"default",
"click_action":"FCM_PLUGIN_ACTIVITY",
"icon":"fcm_push_icon"
},
"data":{
"param1":"value1",
"param2":"value2"
},
"to":"Device token/ID",
"priority":"high",
"restricted_package_name":""
}
let options = new HttpHeaders().set('Content-Type','application/json');
this.http.post("https://fcm.googleapis.com/fcm/send",body,{
headers: options.set('Authorization', 'key=YourAuthToken'),
}).subscribe();
hope this is helpful for you.
Thank You.
Push notification works the same way as local notification with a minor difference. Push notifications require connectivity and a server infrastructure of some kind to send the notification. With local notification you can trigger the notification with conditions. You will get the notification even if the app is closed and you’re offline. And having both notifications won’t cause implications.
In your case, you should go with Push Notification.If in future if you want to change the parameter to send notification it will be easy for you to maintain.No need to update the app
You can use FCM- Firebase Cloud Messaging on server side and in client side you can use PhoneGap push plugins to generate device token
here are the plugins
<plugin name="phonegap-plugin-push" source="npm" spec="1.8.4">
<variable name="SENDER_ID" value="XXXXXXX" />
</plugin>

Push service ionic 2

I have follow this tutorial (https://devdactic.com/ionic-2-push-notifications/#disqus_thread)
I do not receive notification (status sent on ionic.io) on physical iOS Device with TestFlight. (But the token is generated).
app.component.ts and app.module.ts file: https://pastebin.com/HB97KdWL
I have try official tutorial but same problem..
Thank you in advance !
So, there are a bunch of things that could go wrong, especially with ios. Here are some things to look at:
Managing the certificates for the APNS can be rough. If you have
access to an android device, start there since it's a little more
straightforward to get notifications up and running.
Since you're using apps.ionic.io, you have the advantage of checking
to see if you have a push token assigned to a user. (I'm assuming
that you're using auth?) In the Auth tab, select the
user->View->check the push tab to see the token. Also, use the push
service to send a generic push notification to the users to see if
it arrives.
If you have a problem with ios, there's a strong likelihood that
there's something wrong with the certificates... so check for
another tutorial on that. I'd recommend using the Ionic Cloud Services website instead of Devdactics since Ionic is more in-depth. You can find it here: https://docs.ionic.io/services/push/#prerequisites
Make sure that the "Background Notifications" and "Push
Notifications are selected on the General tab in the Xcode project.
Since you're using Ionic, changing anything with 'cordova platform
add ios' can overwrite it. Make sure it looks like this: ![enter
image description here]3
This might be an oversight?...in your code, you have this:
const cloudSettings: CloudSettings = {
'core': {
'app_id': 'XXXXXX' **<-- this should be a value. (not XXXXXX)**
},
'push': {
'sender_id': 'XXXXX', **<-- this should be a value. (not XXXXXX)**
'pluginConfig': {
'ios': {
'badge': true,
'sound': true
},
'android': {
'iconColor': '#ff0000'
}
}
}
};
app_id is something that is covered in the tutorial that you sent. It's under the IOS certificate section. It says, "After going through the Push guide you need to have your App Id from the Identifier you created inside your Apple profile. Copy that ID and open your config.xml and add your ID:" This is the same ID that you'll put in that section of code.
Unfortunately, there are a lot of things that can go wrong with the certificates. I would focus there since the errors that you get can be unannounced.

Rich push notifications in Smartface App Studio

I am trying to integrate push notification in smartface. But, this push notifications are only simple text.
Is there any way i can configure rich push notifications like,
Notification which is combination of images and text.
Please help to resolve this. Thanks in advance.
I think you have to use :
LocalNotification(
id,fireDate, alertTitle, alertBody, alertAction,
userInfo, launchImage, applicationIconBadgeNumber,
hasAction, repeatInterval, sound, smallIcon, autoCancel,
number, when, usesChronometer, vibrate, ticker, subText,
priority, actions, progress, bigText, bigPicture
);
Notifications API

Implement Push notification in Android Phonegap app

Created UI using Angular and Ionic, and wrapper usign Phonegap, How can I have pushnotification in Android implemented.
Is there any effective and accurate library in Phonegap for Pushnotification Implemented.
Already using https://github.com/phonegap-build/PushPlugin, but getting some issues, like push notififcation not received, some time all notification coming at once.
First create a project in Google console
Enable GCM
Create a server api Key
use the following plugin
cordova plugin add phonegap-plugin-push --variable SENDER_ID="XXXXXXX"
replace the xxxxxx with your sender id
n your javascript add the following code for registering to GCM server it will give you a GCM id
var push = PushNotification.init({
android: {
senderID: "XXXXXXXX" //add your sender id here
},
ios: {
alert: "true",
badge: "true",
sound: "true"
},
windows: {}
});
push.on('registration', function(data) {
consol.log(data.registrationId); //this function give registration id from the GCM server if you dont want to see it please comment it
document.getElementById("gcm_id").value= data.registrationId; //showing registration id in our app. If it shows our registration process is suscess
//$("#gcm_id").val(data.registrationId); if you are using jquery
});
Send a message using GCM HTTP connection server protocol:
https://gcm-http.googleapis.com/gcm/send
Content-Type:application/json
Authorization:key=YOUR SERVER KEY
{
"to": "GCM ID",
"data": {
"message": "This is a GCM Topic Message!",
}
}
for more details..
http://phonegaptut.com/2016/05/31/how-to-send-push-notifications-in-phonegap-application/
I was having the same problem lately, using Ionic and Cordova (not Phonegap, but should work the same).
I ended up using this library for local push notifications https://github.com/Wizcorp/phonegap-plugin-localNotifications
They worked pretty well except the PN would not start the app on Android, but I opened a pull request with a fix for that.
If you encounter the same problem, you might also use my fork of this plugin which has this fix already included.
You should be using ngCordova's Push Plugin for this.
From the docs:
Allows your application to receive push notifications. To receive notifications in your controllers or services, listen for pushNotificationReceived event.
As Push Notification is a native feature, so to integrate Push in PhoneGap Android application you have to make a plugin that will communicate with Android Native code.
You can go through with Sample application available on Git Hub.
Please also follow the necessary steps require for it mentioned in ReadME file.

Is it possible to send a "silent" push notification on iPhone (without any alert to the user)?

I need to do it on a chat app to notice the client that there is new data to fetch from the server.
I know that technically it is possible with an empty payload (at least on ios 5 device it worked), but can Apple see it as abuse of service or is it OK to do it?
And is it technically possible on ios 4 device?
Yes, increment only badge number, dont send sound and alert, So, there will be one badge on the App icon.
So, here unknowingly the badge number will be incremented to show that something has been recieved when user watches the app icon.
But your device won't recive alert or empty payload and won't recieve sound also because you asked for “silent” push notification on iPhone
and while configuring in AppDelegate, configure only badges
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge];
Hope this will be helpful for you
You need to build the payload like this:
String payload =
'{
"aps":{
"content-available": 1
},
"data_id": 5,
"additional_data": ["some", "data"]
}'
In aps put the apple variales needed to make the push notification display a text, sound, badge... or just content-available to make it silent. Then, out of 'aps{...}' and separated with ',' put your custom fields to send the needed information for the download.
If you don't want the badge number to increase you could also try sending a sound notification which plays a silent sound file. (Unfortunately, I don't know if this is ok for Apple).