IOS Cordova Push Plugin - Coldstart Crashes App - javascript

I am using the the Cordova Push Plugin: http://ngcordova.com/docs/plugins/pushNotifications/
This works fine in Android Platform. But, for IOS, I face the following issue:
I register listener for '$cordovaPush:notificationReceived' event as per the documentation and provide the same implementation as given in the documentation in the link above (given below for ease):
$rootScope.$on('$cordovaPush:notificationReceived', function(event, notification) {
if (notification.alert) {
navigator.notification.alert(notification.alert);
}
if (notification.sound) {
var snd = new Media(event.sound);
snd.play();
}
if (notification.badge) {
$cordovaPush.setBadgeNumber(notification.badge).then(function(result) {
// Success!
}, function(err) {
// An error occurred. Show a message to the user
});
}
});
There are 3 scenarios:
1. App is running in foreground. In such case, even though the notification arrives (confirmed by log statements), no visible action happens on the device.
I expected the below two statements to execute but they dont.
navigator.notification.alert(notification.alert);
snd.play();
App is running in background. In such case, the statements seem to execute as per expected behaviour.
App is NOT running at all (coldstart). In this case, the notification and sound are played but when user click on notification, the app opens and hangs / crashes.
Has anyone encountered these problems before? What is the best way to solve these? This is only for IOS.

The plugin you are using is deprecated.
i also used it before and there are many issues.
i would reccomend to use the plugin: phonegap-plugin-push
easy to install and will solve your issue

As mentioned by #Nechemya Kanelsky, use the newer version of the push plugin and scenario 1 and 2 will be handled. But with that plugin as well, the 3rd issue still remains, as mentioned here
You can use the fix for 3rd issue, mentioned here

Related

react native expo app ACCESS_BACKGROUND_LOCATION needs to be added to the manifest Problem

i'm building an expo app with the managed flow (so i don't have a direct access to the manifest in android) and i did read and even memorize the documentations and it said that i need to add the permission to the android.permissions in my app.config.json file which i did as follows:
"android": {
"permissions": [
"ACCESS_BACKGROUND_LOCATION",
"ACCESS_COARSE_LOCATION",
"ACCESS_FINE_LOCATION"
]
},
and it's still telling me the same thing , even though according to the doccumentations this is the only thing i need to do to include the permission. but for some reason either the android device is ignoring this or expo is not adding it in the manifest they're building in the background or for whatever reason the app acts just as if i didn't add these lines to the config file.
things i tried :
i tried multiple ways including removing the fine location permission (because somewhere somebody said that the new android update accepts only one location permission ; either fine location or background location) . and that of course didn't work.
building a standalone version of my app (because somebody said that Expo go doesn't allow background location on android)
i've seen multiple issues opened on both github and expo forums about this problem , most noticeably :
1- issue raised on github
2- issue raised on expo forums
i also of course read the following
expo permissions docs
android config docs on expo
the code i'm using to ask for the permission:
try {
// at the following line it just breaks and jumps to the catch block
const { status } = await Location.requestBackgroundPermissionsAsync();
console.log(
"###################### requestBackgroundPermissionsAsync ######################"
);
console.log(status);
console.log(
"###################### requestBackgroundPermissionsAsync ######################"
);
if (status === "granted") // ... the rest of the code
} catch (error) {
console.log(error);
}
the code just breaks with an error at this line and tells me the following :
You need to add `ACCESS_BACKGROUND_LOCATION` to the AndroidManifest.
at node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:103:50 in promiseMethodWrapper
at node_modules/#unimodules/react-native-adapter/build/NativeModulesProxy.native.js:15:23 in moduleName.methodInfo.name
at node_modules/expo-location/build/Location.js:142:7 in requestBackgroundPermissionsAsync
at node_modules/expo-location/build/Location.js:142:22 in requestBackgroundPermissionsAsync
at screens/home/GoToLocation.tsx:156:25 in onGoToLocation
at http://192.168.8.102:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&minify=false:191029:39 in onGoToLocation
at node_modules/react-native/Libraries/Pressability/Pressability.js:691:17 in _performTransitionSideEffects
at node_modules/react-native/Libraries/Pressability/Pressability.js:628:6 in _receiveSignal
at node_modules/react-native/Libraries/Pressability/Pressability.js:524:8 in responderEventHandlers.onResponderRelease
the question is : is this like a bug in expo, and they need to fix it or is it something that i'm doing wrong? and if i'm doing something wrong. PLEASE HELP.
after batteling with it for a couple of days it turned out to be a bug in the new version of the expo go app 2.22.3 which doesn't read or register this type of permission at all . so i just downgraded to the version 2.21.5 and it worked just fine.
this was confirmed by one of expo's maintainers on the issue opened on github
github issue and confirmation
anyways , it seems they're working on it but up until it's fixed just use the older version of the app if you're testing with android.

Hook a Javascript event to fire on another application OR suggestions

We have a web based jquery mobile app that records activity of a user. This app is long standing and in use at the moment, so re-writing the application is not an option unfortunatly.
The problem is that we are trying to get GPS location at certain points using the application.. But as it is running in an instance of chrome, the javascript will not record correctly when the phone is locked, or the chrome is minimised.
So to get around that we are writing an Ionic App with Cordova in order to get the GPS coordinates in the background, regardless of the state of the browser.
Currently, this is working great. The issue however is there are certain events in our javascript that require a specific 'type' associated to our GPS logging.
My question is: How do I actually hook onto this javascript event in CHROME from the GPS background ionic/cordova application.
What we have tried so far:
Finding the chrome localstorage via Ionic/Cordova and reading a value from that on a timer.
The issue with this is we can't find the location of the localstorage/cache.
From this question it says its here:
/data/data/com.android.chrome/cache
but we can't find/access it from our ionic app or file browser on the android
https://android.stackexchange.com/questions/85998/android-google-chrome-browser-cache-location
We have also looked for ways to hook the javascript events to fire something inside the other application but we are having no luck there either..
Apologies for the long post.. Its hard to explain. If you have any suggestions on alternative methods to do this kind of cross-application event firing from Chrome to Ionic/Cordova I would be greatly interested to hear your oppinion.
To fix this I created a 'stack' where I could push an object to an array that would be picked up by the cordova app using executeScript as follows:
In the inappbrowser site:
var stackName = stackN1
function addEventToStack(numid, type) {
var stackRow = { 'numb': numid, 'type': type};
var stack = localGet(stackName); //localstorage
if (!stack)
stack = StackInit();
stack.push(stackRow);
localStore(stackName, stack);
console.log('Added to stack ', stack);
return 'Row Added';
}
In the cordova application:
ref.executeScript(
{
code: 'localStorage.getItem("stackN1")'
},
function(rdObj) {
//Iterate and use rdObj here
}

Service Worker Install fails: "cannot read property 'addAll of undefined"

So I'll keep this succinct: When trying to install, my service worker fails. This is all of my code in sw.js:
var cacheName = 'randomstring';
var filesToCache = [ '/' ];
self.addEventListener('install', function (e) {
console.log('[ServiceWorker] Install');
e.waitUntil(
caches.open(cacheName)
.then(function (cache) {
console.log('[ServiceWorker] About to fail');
return cache.addAll(filesToCache);
})
);
});
I get an exception because cache is undefined (on the cache.addAll bit).
Not really sure why this is the case?
I've used service workers before and never encountered this issue. This is my first time using a service worker with an ASP.Net back-end though, so not sure if that's the problem?
So, I figured this out. I was going to vote to close the question, but I figured I'd leave it here as I saw some other people with this issue who didn't know how to resolve it. Even though it's super-stupid :) (or more accurately, I am).
So I was running the website via the "Play" button, aka "Start Debugging", which, in Visual Studio 2017, launches a special Chrome window, in which the above error will be thrown.
To work around the issue, I can (or you can, internet traveller of the future) simply start without debugging, host the website in IIS, etc.
EDIT: If there's a better workaround where I can use the service worker in debug mode, please suggest it and I'll mark that as the answer. For my specific problem though, the above workaround is fine :).
Encountered the same problem and found some other ways.
VS recognises "chrome.exe" while debugging and adds some parameters, that´s why service workers won´t working.
There is an option Debug => Option => Debugging => General => Enable javascript debugging for asp.net (Chrome, Edge and FireFox). If you don´t want to use js debugging in vs - like me because i use chrome for js debugging - just deactivate this option and service workers will work.
VS Enable JS Debugging in Chrome
Alternatively you can add chrome as a new "browser" and switch the browser for debugging. Because vs recognise "chrome.exe" make a symlink via administative commandline "mklink chromedirect.exe chrome.exe" and add it as new browser in visual studio.
This can be done under the "Play" context menu => Browse with.
VS Play Context Menu
Just add chromedirect.exe without any arguments and a friendly name like "Google Chrome Direct". After that you can switch to the browsers and select if you want VS JS Debugging or not.

HashNavigation in cordova wp8 hangs app

I have next code
function navigate(_hash){
alert('before');
//try#1
window.location.hash = _hash;
//try#2
// window.location.href=window.location.href.split("#")[0]+"#" +url;
alert('after');
}
navigate('someurl')
the issue is that after changing url hash (both variants) app just hangs. And interesting thing that second alert is not firing. so app just... crashes after some time.
Nothing in js console.
Debug log says
The thread 0x*** has exited with code 259 (0x103).
google found nothing on that. Seems like this is acommon error code.
More details:
i'm using ChaplinJs so just can't get away from hash navigation.
second thought was that chaplin overloads system and we caanot get anywhere, but(!) putting logs and alerts in source of lib in window.on('hashchange',....) also didn't make any effort because we do not get there also.
WP 8.0
tried both Cordova 4.* and 5.*
also tried to modify xhrXelper.cs but it is not related tonavigation itself.
PS: I know that jquery mobile suggests to disable hashchanges onmobile navigation. But i can't :(
PPS: also tried todisable chaplin haschanges
new App({routes: routes, controllerSuffix: '-controller', pushState: false,hashChange:true})
but this also didn't make any good results because it's placing hash to href to check it in interval and app hanged again. So i assume that is a webview problem
More additional info:
continious re-run of app makes it work sometimes (1 run of 10 can make it work). That's very strange.
Emulator and device behave in the same way.
Update: Read somewhere that it's critical to restrict navigting before "deviceready" event.
But this is also not a case.
Update2: create cordova proj from scratch. Added hash change indeviceready cb and it hangs
Update3: same code on 8.1 works perfect

PhoneGap application not .live('tap') events on iOS

I have an application that is using jquery, jquerymobile and spine.js running on phonegap (0.9.5.1) and have been having some issues getting it to work properly on iOS.
The application should be launching the camera when a div is tapped. In my controller I have it so that it does something similar to the following:
myController = Spine.Controller.create({
events: {"tap .take-picture": "takePic"},
takePic: function(){
var self = this;
navigator.camera.getPicture(function(data){
self.doStuffWith(data);
},
null,
{quality: 50, destinationType: Camera.DestinationType.DATA_URL, sourceType: Camera.PictureSourceType.CAMERA})
},
doStuffWith: function(data){
// Doing stuff with said data
}
});
What is really confusing me, is that this code works properly on Android. Are there some kind of iOS quirks that make it so that tap events aren't sent off properly?
I think that you are trying to use the Android phonegap js within the iPhone app. You need to make sure that you are including the right phonegap.js for the platform you are developing. Although they share the same name, each version of phonegap is tailored to its host OS.
This could be several things:
You are testing this in the iOS Simulator. There is no Camera in the Simulator, you don't have a fail callback specified, but there is a bug (I believe) in the API where it doesn't call the fail callback if the source type is not available anyway. You should see this ("Source Type Not Available") in the Run Log (Cmd-Shift-R).
On a device, I tested your code separately, and ran it in deviceReady(), it runs - so the API call seems to be correct. I added a touch handler to a button to call the code also, so it appears tap events are working. So based on these tests (on a device):
(a) the API call works
(b) tap events work
Which leads me to the conclusion that the bug is outside of those two possibilities.

Categories