Device Ready ios not working - ios

I know this is repeated like ton of times but I cannot find the way to resolve it.
We have an app running in android with no problems.
But when I install it in my iphone the device ready does not get fired.
The device ready jumps in android but in ios if auto-hide-splash-screen is false it keeps stuck in the splashscreen and deviceready is not fired.
I am making the build with phonegap build.
The version of cordova is 3.7.0
the code of the device ready is
document.addEventListener('deviceready', function() {
alert('listening to device ready'+navigator);
navigator.splashscreen.hide();
}, false);

Try something like :
var onLoad = function(){
document.addEventListener("deviceready", deviceReady, false);
};
var deviceReady = function(){
document.addEventListener("backbutton", exitCordova, false);
alert('listening to device ready'+navigator);
navigator.splashscreen.hide();
};
var exitCordova = function(){
navigator.app.exitApp();
};

Related

Cordova deviceready not firing in iOS

I am using Ionic to build my hybrid app.
On Android my app is running quite fine. Now I was building it for iOS but my entire content that is wrapped inside
document.addEventListener('deviceready', function () {
console.log('dashboard -> device ready');
// copy database to the device
DbAccess.copyDb();
}, false);
is not fired in iOS.
I tried it then with the iOS simulator
$ ionic emulate ios --livereload
and checked the console.log.
Result:
1 709252 log deviceready has not fired after 5 seconds.
2 709253 log Channel not fired: onCordovaInfoReady
I followed the suggestions I found here and via Google but unfortunately without any success (removing ios and re-adding, etc)
My versions:
Cordova: 6.1.1
Ionic: 1.7.14
My Security setup in my index.html:
<meta http-equiv="Content-Security-Policy" content="default-src *; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src 'self' 'unsafe-inline' *">
Inside my config.xml:
<access origin="geo:*" launch-external="yes"/>
<access origin="tel:*" launch-external="yes"/>
<access origin="mailto:*" launch-external="yes"/>
I really have no idea where I could go on to solve that bug. Maybe it is something with the Content-Security-Policy but I have no idea how to fix that.
Thanks in advance for your help!
Edit:
I wrapped my controller(s) now inside
$ionicPlatform.ready(function() {...});
e.g.:
var dashboardCtrl = function ($scope, $ionicPlatform, $cordovaDevice, DbAccess) {
console.log('dashboardCtrl');
$ionicPlatform.ready(function () {
console.log('dashboard -> platform ready');
document.addEventListener('deviceready', function () {
console.log('dashboard -> device ready');
// copy database to the device
DbAccess.copyDb();
}, false);
});
};
dashboardCtrl.$inject = ['$scope', '$ionicPlatform', '$cordovaDevice', 'DbAccess'];
It still fails and throws the "deviceready" error in the console.log while I am testing it with the iOS simulator.
If you are using Ionic why you are manually using document.addEventListener('deviceready', function () the $ionicPlatform.ready give you the same result as the 'deviceready' of the cordova, no need to call deviceready again.
Another thing, you should not put the ready function in custom function of the controller. should not use like this
$scope.logInSubmit = function (details) {}
or
var submit = function () {}
If you check the sample of Ionic you will get better idea of both the items (ex: ionic start myApp tabs)
In Ionic your code can be like this
$ionicPlatform.ready(function() {
console.log('dashboard -> device ready');
//you can load your plugins or custom objects inside this device ready
}
I catch the event with
$ionicPlatform.ready(function () {
...
})
It works on a real device, I had never test on emulator.
I don't think that Content-Security-Policy is the reason that you don't get the event.

KendoUI mobile app, view event afterShow has no access to cordova plugin. Outside event is fine

I have a kendoui applbuilder mobile app. I have installed a custom camerapreview plugin and it works fine. I tried adding an event handler to my view (afterShow) to set something in the camera plugin module:
cordova.plugins.camerapreview.startCamera(
which initializes the camera preview.
the problem seems to be that in this handler cordova.plugins.camerapreview is undefined? Access to this same method in a button handler on the view works fine. I'm assuming this has something to do with dependency? How can i ensure this is loaded? Doesn't make sense to me that it wouldn't be available after the view has loaded and bound the model.
my code looks like:
// Handle "deviceready" event
document.addEventListener('deviceready', onDeviceReady, false);
var mobileApp = new kendo.mobile.Application(document.body, {
skin: 'flat',
initial: 'views/home.html'
});
When using Kendo UI Mobile app with Cordova, make sure to initialize the app in the deviceready event. This will ensure that the Cordova APIs will be available throughout the whole app lifecycle.
// this function is called by Cordova when the application is loaded by the device
document.addEventListener('deviceready', function () {
// hide the splash screen as soon as the app is ready. otherwise
// Cordova will wait 5 very long seconds to do it for you.
navigator.splashscreen.hide();
app = new kendo.mobile.Application(document.body, {
// you can change the default transition (slide, zoom or fade)
transition: 'slide',
// comment out the following line to get a UI which matches the look
// and feel of the operating system
// skin: 'flat',
// the application needs to know which view to load first
initial: 'views/home.html'
});
}, false);

Phonegap-Blackberry backpress issue/how to handle back key in phonegap

when i pressed back key using blackberry simulator then its close my whole application but when i pressed back button which i provided in header then its working fine.how to solved this is? is there any backpress handing in phonegap? Same code for android works fine means it doesn't close application on back key press.
Or
<script type="text/javascript">
// Wait for PhoneGap to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is ready
//
function onDeviceReady() {
blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_BACK,
function() {
history.back();
return false;
});
}
</script>
On config.xml --> <feature id="blackberry.system.event" version="1.0.0"/>

Showing splash screen in PhoneGap/Cordova 1.5.0

I'm trying to get my splash screen to show for my PhoneGap/Cordova native iOS app. The default or boolean for this behavior is set to 'YES'. I'm trying to get the screen to show for 2 seconds. At the moment, it only shows for a split second and then goes right into the app. Since my app does not download any data for the web on start, it loads pretty quickly.
According to this advice, this solution works for some. I'm using the latest Cordova 1.5.0 build: http://shazronatadobe.wordpress.com/2011/09/15/ios-phonegap-splash-screen-control/
I've turned the AutoHideSplashScreen to 'NO' in the Cordova.plist and I'm using this code:
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
setTimeout(function() {
navigator.splashscreen.hide();
}, 2000);
I've tried putting the setTimeout function within a function, but to no avail. Like so:
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function hideSplash() {
setTimeout(function() {
navigator.splashscreen.hide();
}, 2000);
}
And then loading the 'hideSplash()' when the Body loads. But to no avail.
Anything wrong with my code?
OK, I took RespectTheCode's advice and removed the device ready event out of the onLoad function. This is the working code. I'm putting the full code for other's who are learning:
<script>
document.addEventListener("deviceready", onDeviceReady, false);
setTimeout(function() {
navigator.splashscreen.hide();
}, 1000);
</script>
The 1000 is one second for those who don't know. Will not work for less than one second i.e 500. Splash screen just hangs.
This is working for me when I install and app works fine,however, when I restart the device (iPad2) the splash screen hangs like the previous problem (above paragraph) and will not enter the app. Weird bug.
Anyone else experience this?
I'm on iOS 5.1 building with Xcode 4.3.1 and Cordova 1.5.0
I am using Cordova 2.1.0 and now 2.2.0.
When calling navigator.splashscreen.hide(), the Splash Screen didn't disappear.
Using the following code, it worked:
private static native void hideSplashScreen() /*-{
$wnd.Cordova.exec(null, null, "SplashScreen", "hide", []);
}-*/;
Hope this helps

PhoneGap iOS application 'deviceready' event - initial entry vs resume

I am using PhoneGap to create a native iOS app. The app implements an iOS scheme so that it can be invoked from mobile Safari like myapp://?parameters.
The app activities depend on the input parameters, i read those by handling the 'deviceready' event.
The problem is that after initial execution the app remains in the background, and any subsequent calls (from the browser) do not fire another 'deviceready', and as a result i cannot get the new parameters.
Any ideas? Thanks!
Did you manage to get the resume event to fire in the end?
I'm having trouble with this as well - I have the following code:
window.addEventListener('load', function () {
document.addEventListener('deviceready', onDeviceReady, false);
}, false);
function onDeviceReady() {
document.addEventListener('resume', onResume, false);
document.addEventListener('pause', onPause, false);
document.addEventListener('online', onOnline, false);
document.addEventListener('offline', onOffline, false);
}
function onResume() {
alert('resume');
}
function onPause() {
alert('pause');
}
function onOnline() {
alert('online');
}
function onOffline() {
alert('offline');
}
And although the deviceready and online events appear to be firing, I can't seem to get the resume event to fire. Any light anyone could shed on this would be much appreciated!
There is a 'resume' event. http://docs.phonegap.com/phonegap_events_events.md.html
It has been more than a year since the question was asked, but I want to reply for future readers anyway.
If you want your app to respond to url schemes after the initial load( on resume ), you need to define a function called handleOpenURL() in global context. Then this function will automatically be fired when your app resumes.
function handleOpenURL(invokeString) {
// do something with the invoke string
}

Resources