IOS push notification issue on appcelerator - apple-push-notifications

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

Related

how use the eventchannel of flutter for desktop on windows?

I want to use event channel notify the flutter, but I can't find any example about event channel for desktop(windows).
The mothed channel is duplex mode, dart invoke native funtion by "channel" + "funtion" , Similarly, native invoke dart function by the same way.
1、using the cmd:
flutter create -t plugin --platforms=linux,macos,windows window_to_front
2、find the function:
RegisterWithRegistrar
3、using “channel” in “RegisterWithRegistrar” function:
channel->InvokeMethod("foo", nullptr, nullptr)
4、registe the "channel" and "function" in dart:
var channel = MethodChannel("test2");
channel.setMethodCallHandler((call) {
switch(call.method) {
case "foo": {
//String msg = call.arguments["msg"];
print("Native invoke Flutter susscess,params:${call.arguments}");
//return "success";
}
}

Not getting location in Android 8.0.0 Oreo

I am building an app in React-Native and need to have location access as per the requirement.
I have tried using react-native-fused-location for the same, as below.
FusedLocation.setLocationInterval(20000);
FusedLocation.setFastestLocationInterval(15000);
FusedLocation.setSmallestDisplacement(10);
FusedLocation.setLocationPriority(
FusedLocation.Constants.HIGH_ACCURACY
);
FusedLocation.startLocationUpdates();
FusedLocation.getFusedLocation().then(location => {
if (location != null) {
let initialPosition = JSON.stringify(location);
this.state.latitude = location.latitude;
this.state.longitude = location.longitude;
this.state.timestamp = location.timestamp;
this.state.initialPosition = initialPosition;
} else {
alert("Location unavailable, please try later");
}
}).catch(error => { // fused location catch
console.log("location retrieval failed");
});
The only output, I am receiving with the above code, in case of Oreo 8.0.0 is E/request: 100.
also tried the other way as below
navigator.geolocation.watchPosition(
location => {
console.log("inside watchPosition location");
if (location != null) {
console.log("location is not null");
let initialPosition = JSON.stringify(location.coords);
this.state.latitude = location.coords.latitude;
this.state.longitude = location.coords.longitude;
this.state.timestamp = location.coords.timestamp;
this.state.initialPosition = initialPosition;
} else {
alert("Location unavailable, please try later");
}
},
error => {
console.log("calling ShowHideActivityIndicator, getLocationWithNavigate (ios)");
this.ShowHideActivityIndicator(false);
alert("location retrieval failed");
console.log(error);
},
{ timeout: 20000, enableHighAccuracy: true, distanceFilter: 10 }
);
But getting same output in both of the above codes, that is unable to get the location specifically in Android Oreo 8.0.0. Even the location retrieving callback is not even called. Though in other versions, including Oreo 8.1.0, and lower version devices, including Marshmallow and Nougat, it seems working fine.
Though, if I turn on the fake GPS in Oreo 8.0.0, then it seems to be able to get the location. I am unable to figure out, what I am missing.
mention to google document:
In an effort to reduce power consumption, Android 8.0 (API level 26) limits how frequently background apps can retrieve the user's current location. Apps can receive location updates only a few times each hour.Background Location Limits

App published on the stores ENV_TEST is true

I used this within my app:
if(ENV_DEVELOPMENT) {
Ti.API.info('Environment: DEVELOPMENT');
alert('Environment: DEVELOPMENT');
}else if(ENV_TEST) {
Ti.API.info('Environment: TEST');
alert('Environment: TEST');
}else if(ENV_PRODUCTION) {
Ti.API.info('Environment: PRODUCTION');
}
The App has just been published in the stores and it's alerting 'Environment: TEST'.
Is there any reason why a published app should give ENV_TEST = true??

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