OneSignal Notification not working on iOS 10 - xcode

Notifications from OneSiganl for iOS 10 is not working. things i have rechecked again that i am using..
Xcode 8.1,
Swift 3,
Added latest provisioning cert,
Under capabilities push notifications are on with entitlement,
My app delegate methods are
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
OneSignal.initWithLaunchOptions(launchOptions, appId: ONE_SIGNAL_APPID)
OneSignal.setLogLevel(.LL_VERBOSE, visualLevel: .LL_NONE)
OneSignal.promptLocation();
OneSignal.initWithLaunchOptions(launchOptions, appId: ONE_SIGNAL_APPID, handleNotificationReceived: {
(Notification) in
}, handleNotificationAction: { (action) in
}, settings:[kOSSettingsKeyAutoPrompt: true ,
kOSSettingsKeyInFocusDisplayOption:OSNotificationDisplayType.notification.rawValue]) }
And for registering the device with id.
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
OneSignal.sendTag("myType", value: "myBroadCast")
OneSignal.idsAvailable { (userId, deviceToken) in
let userId = String(format: "%#", userId!)
DataManager.sharedInstance.deviceToken = userId;
print("player id",userId)
}
I have got the playerid i.e userId apparently. So my device is registered successfully.
The thing is that the api notifications are not receiving on my device. Other than OneSignal sample push messages (which are working fine),
My API payload for notification is
{"alert":{"notification":{"notification_type":1,"v_n":"Custom Place","u_n":"customer","c_id":907,"m_id":1207,"m_t":"1","f_a":0,"d_d":"07 Dec, 2016","t_t":"07:40 AM","is_group_chat":true},"body":"hxuf"},"badge":1,"sound":"NewMessage.mp3"}
Please help me in this regard. As this problem is only with iOS 10 devices.

If your making a POST REST API call to https://onesignal.com/api/v1/notifications your JSON format isn't correct. The JSON payload should be as follows for the OneSignal notification based on your contents from your JSON example in your question.
{
"app_id": "YOUR_ONESIGNAL_APP_ID",
"contents": {"en": "hxuf"},
"ios_badgeType": "SetTo",
"ios_badgeCount": 1,
"ios_sound":"NewMessage.mp3",
"data": {"notification_type":1,"v_n":"Custom Place","u_n":"customer","c_id":907,"m_id":1207,"m_t":"1","f_a":0,"d_d":"07 Dec, 2016","t_t":"07:40 AM","is_gr`oup_chat":true}
}
Note1: You must set a targeting parameter such as include_player_ids as a JOSN array to a list of OneSignal player / user ids. Or use another targeting parameter such as included_segments. See the full tarting options in the OneSignal documentation page at the bottom of this answer.
Note2: .mp3 files can't be used for notification sounds for iOS. You must convert it to a .wav or .caf format.
See OneSignal's full documentation on the create REST API call endpoint below.
https://documentation.onesignal.com/reference#create-notification

Related

Authentication problem with running ionic app using firebase on native device, everything works fine with live reload

Good morning!
I have a strange problem where i can run & authenticate my user on my ios device perfectly fine running the app using the command below.
ionic capacitor run -l --external
Using an emulator, it works sometimes, though not always.
When I try to deploy the app using Xcode, the app opens and looks normal, but if I try to send authentication requests to firebase, the app just keeps on loading, although the requests are successfully performed.
I first thought the problem was because of using LocalStorage so I rebuilt everything using Ionic Storage. But that didn't help.
I tried different versions of adding the Firebase SDK in Swift or in the Cocoa Pods file but the behaviour doesn't change so I don't believe that this is a issue with a wrong firebase configuration, what is the proper way to do this by the way - or is Ionic doing this for me already?
The output of Xcode doesn't provide any valuable information either.
2021-12-01 11:20:13.990875+0100 App[3162:27661] Writing analzed variants.
2021-12-01 11:20:14.125754+0100 App[3162:27661] KeyboardPlugin: resize mode - native
⚡️ Loading app at capacitor://localhost...
2021-12-01 11:20:14.552490+0100 App[3162:27661] Writing analzed variants.
⚡️ WebView loaded
⚡️ [log] - Angular is running in development mode. Call enableProdMode() to enable production mode.
⚡️ [log] - null
⚡️ To Native -> App addListener 60635511
2021-12-01 11:20:21.393141+0100 App[3162:27661] [Accessibility] WKContentView[#] set up: # pid: # MACH_PORT -830404096
login-function
loginWithEmail() {
let email: string = this.loginForm.get("email").value;
let password: string = this.loginForm.get("password").value;
this.loadingService.present({
message: "Logging in . . ."
});
this.authService
.loginWithEmail(email, password)
.then((result) => {
this.authService.SetUserData(result.user)
this.resetLoginForm();
this.loginSuccess();
this.router.navigateByUrl("/tabs/intensity");
})
.catch(error => {
console.log(error);
this.loginFailed(error);
});
}
login-success
loginSuccess() {
this.loadingService.dismiss();
this.toastService.present({
message: "Welcome back!",
duration: 3000,
color: "secondary"
});
}
login-with-email
import { AngularFireAuth } from "#angular/fire/compat/auth";
...
async loginWithEmail(email: string, password: string) {
return await this.afAuth.signInWithEmailAndPassword(email, password);
}
set user-data function
SetUserData(user) {
this.user = user;
const userRef: AngularFirestoreDocument<any> = this.afs.doc(`users/${user.uid}`);
const userData: User = {
uid: user.uid,
email: user.email,
displayName: user.displayName,
photoURL: user.photoURL,
emailVerified: user.emailVerified
}
return userRef.set(userData, {
merge: true
})
}
Running it multiple times some times I get this error.
API error: <_UIKBCompatInputView: 0x7fb965726040; frame = (0 0; 0 0); layer = <CALayer: 0x600002f718a0>> returned 0 width, assuming UIViewNoIntrinsicMetric
I am really stuck on this and would appreciate any help. Thank you & kind regards.
Ionic 6.18.1
Angular 12.1.5
Xcode Version 13.1 (13A1030d)

iOS push notifications not showing up through Parse local server

I'm doing whatever i can to send ios push notifications to a react-native app and for that app to display notifications.
I've been trying to figure this out for months.
I have a local Parse server running with the following config:
{
"appId": "org.reactjs.native.example.ReactZeroNotifications",
"masterKey": "masterkey",
"databaseURI": "mongodb://localhost/test",
"push": {
"ios": [
{
"pfx": "reactnotification-dev.p12",
"bundleId": "org.reactjs.native.example.ReactZeroNotifications",
"passphrase": "*",
"production": false
},
{
"pfx": "reactnotification-prod.p12",
"bundleId": "org.reactjs.native.example.ReactZeroNotifications",
"passphrase": "*",
"production": true
}
]
}
}
I then send a post request to http://localhost:1337/parse/push with the following headers:
X-Parse-Application-Id: org.reactjs.native.example.ReactZeroNotifications
X-Parse-Master-Key: masterkey
and the following raw JSON data:
{"where": {"deviceType": "ios"},"data":{"alert": "hello NOTIFICATIONS!!"}}
Meanwhile I have a react-native app running with pushnotification linked as a library and I receive the register event with a token.
However, my notification event never goes off and I never see a notification at the top of my iPhone as I'm trying to accomplish.
(Note: I just want to see a notification on a react-native app... no matter how this is accomplished, I feel as if I could figure out the rest if I can just get it to work once)
As per recommendation i turned on verbose on the parse server and received the following after posting:
verbose: sending push to 0 installations
verbose: sent push!
0 success, 0 failures

IOS push notification issue on appcelerator

i have a big problem on my IOS app. I follow the guide provide by appcelerator documentation to setup my iOS push notification. All seemed work fine, on my appcelerator dashboard i see under the device section my device registered with its token, and when i send a push notification on the detail's push (in push notification log) i read my id device number with a perfect Success(1).
But on my device i didn't receive any notification. I tried with my app opened and with my app closed, but nothing has showed. I don't know why this happen. On my android all work fine. Here my code:
//PUSH NOTIFICATION
var Cloud = require("ti.cloud");
//controllo se ho un token
var deviceToken = Ti.App.Properties.getString("deviceToken");
if ( deviceToken == "" || deviceToken == null) {
requireToken();
} else {
if ( Ti.App.Properties.getString("subscribed") !== "true" ) {
subscribeToChannel(deviceToken);
}
}
//chiedo un token
function requireToken() {
// Check if the device is running iOS 8 or later
if (Ti.Platform.name == "iPhone OS" && parseInt(Ti.Platform.version.split(".")[0]) >= 8) {
Ti.API.warn( "entrato nella versione" )
// Wait for user settings to be registered before registering for push notifications
Ti.App.iOS.addEventListener('usernotificationsettings', function registerForPush() {
// Remove event listener once registered for push notifications
Ti.App.iOS.removeEventListener('usernotificationsettings', registerForPush);
Ti.Network.registerForPushNotifications({
success: deviceTokenSuccess,
error: deviceTokenError,
callback: receivePush
});
});
// Register notification types to use
Ti.App.iOS.registerUserNotificationSettings({
types: [
Ti.App.iOS.USER_NOTIFICATION_TYPE_ALERT,
Ti.App.iOS.USER_NOTIFICATION_TYPE_SOUND,
Ti.App.iOS.USER_NOTIFICATION_TYPE_BADGE
]
});
}
// For iOS 7 and earlier
else {
Ti.Network.registerForPushNotifications({
// Specifies which notifications to receive
types: [
Ti.Network.NOTIFICATION_TYPE_BADGE,
Ti.Network.NOTIFICATION_TYPE_ALERT,
Ti.Network.NOTIFICATION_TYPE_SOUND
],
success: deviceTokenSuccess,
error: deviceTokenError,
callback: receivePush
});
}
function deviceTokenSuccess(e) {
Ti.API.warn( "token ricevuto" )
Ti.App.Properties.setString("deviceToken", e.deviceToken);
subscribeToChannel(e.deviceToken);
}
function deviceTokenError(e) {
//error action
}
}
//controllo se sono iscritto alle notifiche push
if ( Ti.App.Properties.getString("subscribed") !== "true" ) {
subscribeToChannel(deviceToken);
}
function subscribeToChannel (_deviceToken) {
Ti.API.warn( "subscribe fatta" )
Cloud.PushNotifications.subscribeToken({
device_token: _deviceToken,
channel: "ios_alerts",
type: Ti.Platform.name == 'android' ? 'android' : 'ios'
}, function (e) {
if (e.success) {
Ti.App.Properties.setString("subscribed", "true");
}
});
};
function receivePush(e) {
Ti.API.warn("alert ricevuto" + JSON.stringify(e) )
alert(e)
}
is probably something related to your certificates on Apple panel.
Check if you enabled APS with your appid and if not, activate it, then generate another provisioning profiles and re-build the app.
You will also have to put a .p12 file in the Appcelerator platform website.
Just in case this is your issue(s):
Device Token Cannot be fetched if on Device in Debug mode, must be in Run Mode!
Remember that under ad-hock releases push notifications MUST use the sandbox 'gateway.sandbox.push.apple.com'
Chris
Ref: https://archive.appcelerator.com/question/148135/no-reply-from-tinetworkregisterforpushnotifications

Using Parse push as stand alone service

I am building and iOS and Android app (two apps).
I am looking for a replacement for Urban Airship which I do not longer trust. Mainly
because I see no prices anywhere.
I want to use Parse Push as a stand alone product. Is this possible?
I do not want to use any of the other Parse functionality.
As explained in the Parse Push notification ( iOS like Android ) setup at https://parse.com/docs/push_guide#setup/iOS
Yes, you could. Of course you will need to include the parse sdk, since you'll need to register the devices through the Parse system. So:
Once you register the device for receiving push notification ( iOS example )
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
// Store the deviceToken in the current Installation and save it to Parse.
PFInstallation *deviceInstallation = [PFInstallation currentInstallation];
[deviceInstallation setDeviceTokenFromData:deviceToken];
// this will be used later for sending push notifcations to this device
[deviceInstallation setChannels:#[deviceToken]];
[deviceInstallation saveInBackground];
}
Sending Push notification through iOS
PFPush *pushObj = [[PFPush alloc] init];
NSString* destDeviceToken = #"<DESTIONATION DEVICE TOKEN>";
// Through channels, you can uniquely identify devices or group of them for multicast
// push notification (imagine that more than one installation on your
// Parse database keep the same channel name).
// In this case we have set the channel name for each installation with the
// only unique deviceToken
[pushObj setChannels:#[destDeviceToken]];
// Push structure message
[pushObj setData:#{#"My Message!!",#"alert"}];
// send push ( so, send to parse server that handle the push notification
// request and deliver it for you)
[pushObj sendPushInBackground];
Sending Push notification through Android
String destDeviceToken = "<DESTIONATION DEVICE TOKEN>";
JSONObject data = new JSONObject("{\"alert\": \"My Message!!\"}");
ParsePush *push = new ParsePush();
push.setChannel(destDeviceToken);
push.setData(data);
push.sendPushInBackground();
Sending Push notification through Javascript (Cloud Code)
(it requires implementation on the Cloud code of Parse)
var destDeviceToken = '<DESTIONATION DEVICE TOKEN>';
Parse.Push.send({
channels: [ destDeviceToken ],
data: {
alert: "My Message!!"
}
}, {
success: function() {
// Push was successful
},
error: function(error) {
// Handle error
}
});
Sending Push notification through REST call
(it allow you to perform a sending push notification without working on Parse anymore, so from any other platform that support a REST call)
curl -X POST \
-H "X-Parse-Application-Id: <YOUR PARSE APP ID>" \
-H "X-Parse-REST-API-Key: <YOUR REST API KEY>" \
-H "Content-Type: application/json" \
-d '{
"channels": [
"<DESTIONATION DEVICE TOKEN>"
],
"data": {
"alert": "My Message!!",
}
}' \
https://api.parse.com/1/push
In this way you don't need any additional implementation, like registering users or something like that.
Hope it helps!

phonegap build and pushwoosh gets error aps environment not found?

I´m trying to get the pushwoosh plugin to work in a phonegap build app and all I get is an alert error that the aps environment is not found.
This is the steps I took.
Created a new appID that I enabled push notification on.
Created a new APNs Development Certificate. And downloaded it.
Created a new mobile provisioning profile and downloaded it and installed it on my phone.
Checked the mobile provisioning profile that it had "aps-environment" and "developer" in it.
In key chain I rightclicked the aps certificate and exported a .cer and a .p12 file and uploaded them to my newly created application on pushwoosh.com
I wrote the pushwoosh application id in my index file and the right id in the config file(same as in my mobile provisioning file)
I rightclicked my iPhone Developer Certificate in key chain and exported a .p12 file for phonegap and called it mypushapp.p12.
I created a new key at phonegap build and uploaded the mypushapp.p12 and the mobile provising file and then I build my app.
The app itself works as it should, but I get this aps error that it failed to register?
In my index file I init pushwoosh in the deviceready function and this is the pushwooshcode that I have.
function initPushwoosh() {
alert("init pushwoosh");
var pushNotification = window.plugins.pushNotification;
pushNotification.onDeviceReady();
pushNotification.registerDevice({alert:true, badge:true, sound:true, pw_appid:"5FB5C-E3F1F", appname:"newpushtest"},
function(status) {
var deviceToken = status['deviceToken'];
console.warn('registerDevice: ' + deviceToken);
},
function(status) {
console.warn('failed to register : ' + JSON.stringify(status));
navigator.notification.alert(JSON.stringify(['failed to register ', status]));
});
pushNotification.setApplicationIconBadgeNumber(0);
pushNotification.getTags(function(tags) {
console.warn('tags for the device: ' + JSON.stringify(tags));
},
function(error) {
console.warn('get tags error: ' + JSON.stringify(error));
});
//start geo tracking. PWTrackSignificantLocationChanges - Uses GPS in foreground, Cell Triangulation in background.
pushNotification.startLocationTracking('PWTrackSignificantLocationChanges',
function() {
console.warn('Location Tracking Started');
});
document.addEventListener('push-notification', function(event) {
var notification = event.notification;
navigator.notification.alert(notification.aps.alert);
//to view full push payload
//navigator.notification.alert(JSON.stringify(notification));
pushNotification.setApplicationIconBadgeNumber(0);
});
}
I don´t know where I go wrong so any input appreciated thanks.

Resources