I deviceready doesn’t fire or fires very late in my ionic app when I run it on my iOS device with
ionic run ios --device -lcs
I removed all the plugins with ionic plugin rm ...
, deleted the content of the plugins/
directory and reinstalled them.
I also removed and reinstalled the ios platform with ionic platform rm/add ios
.
I am stuck with this.
The iPhone (6+) is on iOS 10.
I am using ionic 1, and the last ionic CLI.
Any idea ?
Thanks
Process 663 detached
(lldb)
(node:26790) DeprecationWarning: Using Buffer without `new` will soon stop working. Use `new Buffer()`, or preferably `Buffer.from()`, `Buffer.allocUnsafe()` or `Buffer.alloc()` instead.
14 030280 warn Native: deviceready did not fire within 2000ms. This can happen when plugins are in an inconsistent state. Try removing plugins from plugins/ and reinstalling them.
15 030605 info [object Object]
16 033286 log deviceready has not fired after 5 seconds.
17 033290 log Channel not fired: onCordovaInfoReady
18 033293 log Channel not fired: onCordovaConnectionReady
19 363977 log DEVICE READY FIRED AFTER, 32259, ms
Here’s my run.js:
/* globals angular, navigator, window */
angular
.module('BoardLine.run', [])
.run(
[ '$rootScope','$translate','$cordovaGoogleAnalytics','connectionStatus','updateProDB','$ionicPlatform','$q','$cordovaStatusBar','$cordovaSplashscreen','storageService','imagesService','UserService','usersDatabase','MigrationService','$ionicDeploy','$state','$timeout',
function ($rootScope , $translate , $cordovaGoogleAnalytics , connectionStatus , updateProDB , $ionicPlatform , $q , $cordovaStatusBar , $cordovaSplashscreen , storageService , imagesService , UserService , usersDatabase , MigrationService , $ionicDeploy , $state , $timeout) {
'use strict';
//We update the database and all
MigrationService.UpdateDesignDocs(usersDatabase,DESIGN_DOCS);
$rootScope.imagesUrlsAreStored = $q.defer();
$rootScope.prodataIsStored = $q.defer();
//$rootScope.isMobile = ionic.Platform.isWebView();
$rootScope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams){
$rootScope.previousState = fromState;
$rootScope.previousParams = fromParams;
});
$rootScope.$on('$translateChangeSuccess', function (event, data) {
document.documentElement.setAttribute('lang', data.language);// sets "lang" attribute to html to be able to tune css upon language
});
// AdMob
// var $rootScope.admobid = {};
if( ionic.Platform.isAndroid() ) {
$rootScope.admobid = { // for Android
// banner: '0',
interstitial: 'ca-app-pub-8847512660775862/1367749437',
interstitialTesting: false
};
} else if( ionic.Platform.isIOS() ) {
$rootScope.admobid = { // for iOS
//for now iOS version is a paid app !
};
}
function initAds() {
console.log("initAds is run");
if(typeof AdMob === "undefined"){
console.log( 'admob plugin not ready, AdMob is undefined' ); return;
} else {
// //this will create a banner on startup
// AdMob.createBanner( {
// adId: $rootScope.admobid.banner,
// position: AdMob.AD_POSITION.BOTTOM_CENTER,
// isTesting: true, // TODO: remove this line when release
// overlap: false,
// offsetTopBar: false,
// bgColor: 'black',
// autoShow:true
// } );
// this will load a full screen ad on startup
AdMob.prepareInterstitial({
adId: $rootScope.admobid.interstitial,
isTesting: $rootScope.admobid.interstitialTesting, // TODO: remove this line when release
autoShow: false
});
}
}
$ionicPlatform.ready(function () {
console.log("Platform Ready !")
if( ionic.Platform.isAndroid() ) {
initAds();
}
$ionicDeploy.check().then(function(snapshotAvailable) {
// When snapshotAvailable is true, you can apply the snapshot
if (snapshotAvailable) {
$ionicDeploy.download().then(function() {
$ionicDeploy.extract().then(function(){
$ionicDeploy.load();
});
});
}
});
$rootScope.isMobile = ionic.Platform.isWebView();
//$ionicAnalytics.register();
if (typeof analytics !== "undefined") {
//DEBUG
//$cordovaGoogleAnalytics.debugMode();
$cordovaGoogleAnalytics.startTrackerWithId("UA-54266735-2");
} else {
console.log("Google Analytics plugin Unavailable");
}
//DEBUG
// localStorage.clear();
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
// cordova.plugins.Keyboard.shrinkView(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
//StatusBar.styleDefault();
//StatusBar.style(1);
$cordovaStatusBar.styleLightContent();
}
if ($rootScope.isMobile) {
if (navigator.globalization) {
navigator.globalization.getPreferredLanguage(function (language) {
$translate.use((language.value).split('-')[0]).then(function (data) {
console.log('SUCCESS -> ' + data);
}, function (error) {
console.log('ERROR -> ' + error);
});
}, null);
}
} else {
var lang;
if (navigator.userLanguage) {// Explorer
lang = navigator.userLanguage;
} else if (navigator.language) { // FF
lang = navigator.language;
} else {
lang = 'en';
}
$translate.use(lang.split('-')[0]).then(function (data) {
console.log('SUCCESS -> ' + data);
}, function (error) {
console.log('ERROR -> ' + error);
});
//DEBUG
//$translate.use('sp');
//console.log('lang',lang);
}
if ($rootScope.isMobile) {
cordova.getAppVersion(function (version) {
if (!storageService.get('appVersion')) {
storageService.persist('appVersion', 0);
}
var PrevAppVersion = storageService.get('appVersion');
if (version !== PrevAppVersion) {
storageService.persist('thisIsANewAppVersion', '1');
var user = storageService.get('user');
localStorage.clear();
UserService.setUser(user);
} else {
storageService.persist('thisIsANewAppVersion', '0');
}
storageService.persist('appVersion', version);
});
}
//DEBUG
//storageService.destroy('imagesUrls');
console.log('connectionStatus: ', connectionStatus.f());
var promiseUpdateProDB = updateProDB.get(),
oldCount = storageService.get('sessionCounter'),
newCount = oldCount === null ? 1 : parseInt(oldCount, 10) + 1;
promiseUpdateProDB.then(
function () {
var prodata = storageService.get('prodata');
//console.log(prodata[2])
imagesService.manageStoredImageUrlsNew(prodata);
//console.log('storageService.get('imagesUrls')........................',storageService.get('imagesUrls'))
$rootScope.imagesUrlsAreStored.resolve();
if (storageService.get('onboardingDone') === 'yes') {
$state.go('app.weightlevel').then(function() {
if ($rootScope.isMobile){
$cordovaSplashscreen.hide();
}
});
} else {
$state.go('app.onboarding').then(function() {
if ($rootScope.isMobile){
$timeout(function () {
$cordovaSplashscreen.hide();
}, 1000);
}
});
}
// if ($rootScope.isMobile){
// $timeout(function () {
// $cordovaSplashscreen.hide();
// }, 1000);
// }
},
function (error) {
$rootScope.imagesUrlsAreStored.reject(error);
console.log('imagesUrl have not been managed !!')
}
);
// ONESIGNAL PUSH NOTIFICATIONS
// window.plugins.OneSignal.setLogLevel({logLevel: 4, visualLevel: 4});
// var notificationOpenedCallback = function(jsonData) {
// console.log('notificationOpenedCallback: ' + JSON.stringify(jsonData));
// };
var notificationOpenedCallback = function(result) {
var data = result.notification.payload.additionalData;
if (data && data.targetUrl) {
console.log("data.targetUrl", data.targetUrl);
//var state = $injector.get($state);
//state.go(data.targetUrl);
$state.go(data.targetUrl);
}
};
if ($rootScope.isMobile) {
window.plugins.OneSignal
.startInit("8e9f4104-3393-4ee4-9061-1d07a4d56e38", "1039432660734")
.handleNotificationReceived(function(jsonData) {
//alert("Notification received:\n" + JSON.stringify(jsonData));
console.log('Did I receive a notification: ' + JSON.stringify(jsonData));
})
.handleNotificationOpened(notificationOpenedCallback)
.inFocusDisplaying(window.plugins.OneSignal.OSInFocusDisplayOption.InAppAlert)
.endInit();
//DEBUG !!! infocusdisplaying
}
// Sync hashed email if you have a login system or collect it.
// Will be used to reach the user at the most optimal time of day.
// window.plugins.OneSignal.syncHashedEmail(userEmail);
//user sessions counter
storageService.persist('sessionCounter', newCount);
});
}
]);