Ionic Core lnitiates inconsistently on real iOS device

I’m experiencing a problem that i can’t seem to figure out.

Whenever i run my ionic app on a real iOS device it sometimes works perfectly and sometimes freezes (after the splash screen hides). I’m suspecting that a plugin is failing to load causing the app to break.

Here are some details, hopefully there’s a problem with my coding:

Cordova CLI: 6.0.0
Ionic Version: 1.2.4-nightly-1917
Ionic CLI Version: 1.7.14
Ionic App Lib Version: 0.7.0
ios-deploy version: 1.8.4 
ios-sim version: 5.0.6 
OS: Mac OS X El Capitan
Node Version: v5.4.1
Xcode version: Xcode 7.2.1 Build version 7C1002

These are the plugins i’m currently using:

cordova-plugin-console 1.0.2 "Console"
cordova-plugin-device 1.1.0 "Device"
cordova-plugin-inappbrowser 1.3.0 "InAppBrowser"
cordova-plugin-splashscreen 3.2.0 "Splashscreen"
cordova-plugin-statusbar 2.1.1 "StatusBar"
cordova-plugin-whitelist 1.2.0 "Whitelist"
cordova-plugin-x-toast 2.4.0 "Toast"
ionic-plugin-keyboard 1.0.8 "Keyboard"
phonegap-plugin-push 1.5.3 "PushPlugin"

app.js file:

angular.module('starter', ['ionic','ionic.service.core', 
'starter.controllers', 'firebase', 'tagged.directives.autogrow', 'ui.calendar', 'ngCordova'])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {

if (window.cordova && window.cordova.plugins.Keyboard) {
  cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
  cordova.plugins.Keyboard.disableScroll(true);
}

if (window.StatusBar) {
  // org.apache.cordova.statusbar required
  StatusBar.styleDefault();
}

var push = new Ionic.Push();

push.register(function(token) {
  console.log("Device token:",token.token);
  var tokenRef = new Firebase('https://myfirebaseapp.firebase.com/PushTokens');

  tokenRef.on('value', function(data){
    console.log(data.val());
    var exists = false;

          data.forEach(function(child){
            console.log(child.val());
            if (child.val().token == token.token){
              console.log('found match');
              exists = true;
              return true;
            }
          });

      if (exists === false){
        console.log('nothing found, add token');
        tokenRef.push({ "token": token.token });
      }
  });
});

  });
})

.config(function($stateProvider, $urlRouterProvider, $ionicConfigProvider) {
if (ionic.Platform.isIOS()){
    $ionicConfigProvider.scrolling.jsScrolling(true);
  }
    $ionicConfigProvider.views.swipeBackEnabled(false);

$stateProvider

.state('app', {
url: '/app',
abstract: true,
templateUrl: 'templates/menu.html',
controller: 'AppCtrl'
})

.state('app.contacts', {
url: '/contacts',
views: {
  'menuContent': {
    templateUrl: 'templates/contacts.html',
			controller: 'ContactsCtrl'
  }
}
})

etc etc .......
});

my index.html:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>

<link href="lib/fullcalendar/dist/fullcalendar.css" rel="stylesheet">

<!-- compiled css output -->
<link href="css/ionic.app.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">

<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="js/ng-cordova.min.js"></script>
<script src="lib/ionic-platform-web-client/dist/ionic.io.bundle.min.js"></script>

<!--<script src="js/ionic-ion-autoListDivider.js"></script>-->
<!-- cordova script (this will be a 404 during development) -->
<!-- Cordova is bootstrapped by ionic-platform-web-client, uncomment this if you remove ionic-platform-web-client... -->
<!-- <script src="cordova.js"></script> -->

       <!-- your app's js -->
	<!-- Firebase -->
	<script src="js/firebase.js"></script>

	<!-- AngularFire -->
	<script src="js/angularfire.min.js"></script>
	<script src="js/taggedAutogrow.min.js"></script>
	<script src="js/md5.min.js"></script>
        <script src="js/app.js"></script>
        <script src="js/controllers.js"></script>
	<script type="text/javascript" src="lib/jquery/dist/jquery.min.js"></script>
	<script type="text/javascript" src="lib/moment/min/moment.min.js"></script>
	<script type="text/javascript" src="lib/fullcalendar/dist/fullcalendar.min.js"></script>
	<script type="text/javascript" src="lib/fullcalendar/dist/gcal.js"></script>
	<script type="text/javascript" src="lib/angular-ui-calendar/src/calendar.js"></script>
  </head>

 <body ng-app="starter">
 <ion-nav-view></ion-nav-view>
</body>
</html>

This is my log output on a real iOS device when the app Freezes:

2016-02-15 20:13:15.388 My App Name[780:219212] Apache Cordova native platform version 4.0.1 is starting.
2016-02-15 20:13:15.392 My App Name[780:219212] Multi-tasking -> Device: YES, App: YES
2016-02-15 20:13:15.699 My App Name[780:219212] Using UIWebView
2016-02-15 20:13:15.705 My App Name[780:219212] [CDVTimer][handleopenurl] 0.474989ms
2016-02-15 20:13:15.712 My App Name[780:219212] [CDVTimer][intentandnavigationfilter] 6.397963ms
2016-02-15 20:13:15.713 My App Name[780:219212] [CDVTimer][gesturehandler] 0.388026ms
2016-02-15 20:13:15.756 My App Name[780:219212] [CDVTimer][splashscreen] 42.842031ms
2016-02-15 20:13:15.787 My App Name[780:219212] [CDVTimer][statusbar] 30.280054ms
2016-02-15 20:13:15.789 My App Name[780:219212] [CDVTimer][keyboard] 1.281977ms
2016-02-15 20:13:15.790 My App Name[780:219212] [CDVTimer][TotalPluginStartup] 84.995031ms
2016-02-15 20:13:15.807 My App Name[780:219212] active
2016-02-15 20:13:15.809 My App Name[780:219212] PushPlugin skip clear badge
2016-02-15 20:13:16.579 My App Name[780:219212] Resetting plugins due to page load.
2016-02-15 20:13:18.245 My App Name[780:219212] Finished load of: file:///var/mobile/Containers/Bundle/Application/1C64E20A-49FF-456D-BED0-969E234A8A54/My%20App%20Name.app/www/index.html#/app/notes

And here is a log output when the app Works! Please note this is the same build, i just hard closed and launched the app again:

2016-02-15 20:22:38.610 My App Name[785:220502] Apache Cordova native platform version 4.0.1 is starting.
2016-02-15 20:22:38.615 My App Name[785:220502] Multi-tasking -> Device: YES, App: YES
2016-02-15 20:22:38.965 My App Name[785:220502] Using UIWebView
2016-02-15 20:22:38.972 My App Name[785:220502] [CDVTimer][handleopenurl] 0.477016ms
2016-02-15 20:22:38.979 My App Name[785:220502] [CDVTimer][intentandnavigationfilter] 6.392002ms
2016-02-15 20:22:38.980 My App Name[785:220502] [CDVTimer][gesturehandler] 0.386953ms
2016-02-15 20:22:39.020 My App Name[785:220502] [CDVTimer][splashscreen] 39.930999ms
2016-02-15 20:22:39.050 My App Name[785:220502] [CDVTimer][statusbar] 29.722035ms
2016-02-15 20:22:39.052 My App Name[785:220502] [CDVTimer][keyboard] 1.286030ms
2016-02-15 20:22:39.053 My App Name[785:220502] [CDVTimer][TotalPluginStartup] 81.809998ms
2016-02-15 20:22:39.071 My App Name[785:220502] active
2016-02-15 20:22:39.073 My App Name[785:220502] PushPlugin skip clear badge
2016-02-15 20:22:39.848 My App Name[785:220502] Resetting plugins due to page load.
2016-02-15 20:22:43.562 My App Name[785:220502] Finished load of: file:///var/mobile/Containers/Bundle/Application/54A4B53F-F144-4CD3-BC76-A738BC266D93/My%20App%20Name.app/www/index.html#/app/notes
2016-02-15 20:22:43.970 My App Name[785:220502] Ionic Core: plugins are ready
2016-02-15 20:22:43.988 My App Name[785:220502] THREAD WARNING: ['StatusBar'] took '16.850830' ms. Plugin should use a background thread.
2016-02-15 20:22:43.991 My App Name[785:220502] Ionic Push: register
2016-02-15 20:22:44.008 My App Name[785:220566] Push Plugin register called
2016-02-15 20:22:44.009 My App Name[785:220566] PushPlugin.register: setting badge to false
2016-02-15 20:22:44.009 My App Name[785:220566] PushPlugin.register: clear badge is set to 0
2016-02-15 20:22:44.009 My App Name[785:220566] PushPlugin.register: better button setup
2016-02-15 20:22:44.017 My App Name[785:220566] GCM Sender ID (null)
2016-02-15 20:22:44.017 My App Name[785:220566] Using APNS Notification
2016-02-15 20:22:44.058 My App Name[785:220502] Push Plugin register success: <A valid token number removed for forum viewing>
2016-02-15 20:22:44.336 My App Name[785:220502] Device token: A valid token number removed for forum viewing
2016-02-15 20:22:44.550 My App Name[785:220502] Firebase is connected

Thank you.

Be sure to wrap all plugin calls in a Device Ready. If you dont and the app is not ready when calling a plugin the app stops.

It is, please check the app.js file or highlight what should change.

I dont see problems. Did you tested the app in a browser (chrome)?
Did you look the console message in the browser debug window??
Can you show me a dump of the console messages?

Anoither issue I once had. Sometimes the emulator is messed up. Firs in the menu of the IOS simulator klik on reset. This takes a few seconds. No run the app in xcode again.

Hi thanks for your response.

Yes it’s been tested and developed on chrome. No errors in the console log. It works every time on there and it also works every time on the emulator, my issue isn’t in that. I believe it works because Ionic native push notifications can’t be used in chrome or ios emulator. Ionic push debug mode is working successfully on chrome.

My issue is running it on a real iOS device, if the app works, everything works (including native push notifications), otherwise it freezes after the splashscreen has loaded.

Looking at the console messages posted above I notice Ionic Core isn’t initiating.

Maybe there’s a bug in that?

I have an app with all of it running. Native Ionic Push notifications, Ionic Deploy, Ionic analytics etc.
If I start the app in xcode I see a message that native Pushnotifications not working in the simulator.
But if a run the app on a real device iPad or iPhone from xcode Pushnotification is regeistered etc. On a real device this works.
My experience is that if the app stops most of the time it is because the app is trying to call a plugin before deviceReady. Try to find out how far your app is running by inserting console.log messages. Look in Chrome console what is the last message before the app stops.

I agree, that’s what i think too. I’ll see if i can narrow down the problem. Also i’ve seen other posts mentioning Ionic Core and Firebase get into a bit of a cat fight when the app runs. wrapping the firebase calls in device ready has stabilised the app a bit more, but it still hasn’t solved the app from randomly freezing. For the time being i just have to live with it until i’ve found a solution.

Hey, i had the same problem and followed your thread. After reading https://issues.apache.org/jira/browse/CB-10530 the following changes fixed it for me.
https://github.com/shazron/cordova-ios/commit/12a4ffaf85909176e01cba41110ca1d14bcb0804

Thank you. I’ll give it a try. I’m guessing this might get fixed in the next cordova ios release?

Thank you. The new Cordova iOS 4.1.0 fixed the issue for me.

I took the following steps:

sudo npm update -g cordova ionic
rm -rf plugins
rm -rf platforms
ionic hooks add
ionic platform add ios@4.1.0
ionic build ios
cordova prepare
2 Likes