[SOLVED] iOS App works perfect while emulate but not after build


#1

Hi Everyone,
I struggle with a strange problem in my ionic 2 application…
When I testing my app by command:

ionic emulate ios -lc

At first launch, it reports a failure of two plugins:

  • cordova-plugin-app-version
  • onesignal-cordova-plugin

so when I installed correctly by ionic plugin add <PLUGIN-NAME> --save it works fine.

Next I successfully build app by ionic build ios, it signs correctly.

When I try testing on iPhone I notice that two plugins mentioned earlier do not work properly…

So my question is what could be the reason of this issue, Am I missing something?

What I’ve already tried:

  • remove & add platform ios
  • remove & add all plugins
  • ionic state reset
  • ionic run ios, ionic prepare ios

My Xcode console:

2017-04-24 19:21:14.714019+0200 Mobile Med[890:235276] Apache Cordova native platform version 4.3.1 is starting.
2017-04-24 19:21:14.714251+0200 Mobile Med[890:235276] Multi-tasking -> Device: YES, App: YES
2017-04-24 19:21:14.943261+0200 Mobile Med[890:235276] Using UIWebView
2017-04-24 19:21:14.946907+0200 Mobile Med[890:235276] [CDVTimer][handleopenurl] 0.250995ms
2017-04-24 19:21:14.951813+0200 Mobile Med[890:235276] Unlimited access to network resources
2017-04-24 19:21:14.952052+0200 Mobile Med[890:235276] [CDVTimer][intentandnavigationfilter] 4.977047ms
2017-04-24 19:21:14.952483+0200 Mobile Med[890:235276] [CDVTimer][gesturehandler] 0.345945ms
2017-04-24 19:21:14.983199+0200 Mobile Med[890:235276] [CDVTimer][splashscreen] 30.620992ms
2017-04-24 19:21:15.001945+0200 Mobile Med[890:235276] [CDVTimer][statusbar] 18.435001ms
2017-04-24 19:21:15.008616+0200 Mobile Med[890:235276] [CDVTimer][keyboard] 6.324053ms
2017-04-24 19:21:15.008871+0200 Mobile Med[890:235276] [CDVTimer][TotalPluginStartup] 62.243044ms
2017-04-24 19:21:15.101480+0200 Mobile Med[890:235318] libMobileGestalt MobileGestaltSupport.m:153: pid 890 (Mobile Med) does not have sandbox access for frZQaeyWLUvLjeuEK43hmg and IS NOT appropriately entitled
2017-04-24 19:21:15.101597+0200 Mobile Med[890:235318] libMobileGestalt MobileGestalt.c:550: no access to InverseDeviceID (see <rdar://problem/11744455>)
2017-04-24 19:21:16.522218+0200 Mobile Med[890:235276] Resetting plugins due to page load.
2017-04-24 19:21:23.766642+0200 Mobile Med[890:235276] Finished load of: file:///var/containers/Bundle/Application/79E4ACC8-3A93-45E0-9653-9389630F7CC5/Mobile%20Med.app/www/index.html
2017-04-24 19:21:24.213976+0200 Mobile Med[890:235276] DEVICE READY FIRED AFTER 6527 ms

Ionic info:

Your system information:

Cordova CLI: 6.5.0 
Ionic Framework Version: 2.2.0
Ionic CLI Version: 2.2.2
Ionic App Lib Version: 2.2.1
Ionic App Scripts Version: 1.2.5
ios-deploy version: 1.9.1 
ios-sim version: 5.0.13 
OS: macOS Sierra
Node Version: v7.8.0
Xcode version: Xcode 8.3.2 Build version 8E2002

Ionic plugins:

cordova-plugin-app-event 1.2.0 "Application Events"
cordova-plugin-app-version 0.1.9 "AppVersion"
cordova-plugin-badge 0.7.4 "Badges"
cordova-plugin-console 1.0.6 "Console"
cordova-plugin-device 1.1.5 "Device"
cordova-plugin-splashscreen 4.0.2 "Splashscreen"
cordova-plugin-statusbar 2.2.2 "StatusBar"
cordova-plugin-whitelist 1.3.2 "Whitelist"
cordova.plugins.diagnostic 3.1.7 "Diagnostic"
ionic-plugin-keyboard 2.2.1 "Keyboard"
onesignal-cordova-plugin 2.0.11 "OneSignal Push Notifications"

Ionic platforms:

Installed platforms:
  ios 4.3.1

Config.xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="mobmed" version="1.0.7" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
  <name>...</name>
  <description>...</description>
  <author email="..." href="...">..</author>
  <content src="http://10.20.20.138:8100" original-src="index.html"/>
  <access origin="*"/>
  <allow-navigation href="*"/>
  <allow-navigation href="http://10.20.20.138:8100"/>
  <allow-intent href="http://*/*"/>
  <allow-intent href="https://*/*"/>
  <allow-intent href="tel:*"/>
  <allow-intent href="sms:*"/>
  <allow-intent href="mailto:*"/>
  <allow-intent href="geo:*"/>
  <preference name="webviewbounce" value="false"/>
  <preference name="UIWebViewBounce" value="false"/>
  <preference name="DisallowOverscroll" value="true"/>
  <preference name="android-minSdkVersion" value="16"/>
  <preference name="BackupWebStorage" value="none"/>
  <preference name="SplashMaintainAspectRatio" value="true"/>
  <preference name="SplashScreenDelay" value="6000"/>
  <preference name="FadeSplashScreen" value="false"/>
  <preference name="SplashScreen" value="screen"/>
  <preference name="AutoHideSplashScreen" value="false"/>
  <preference name="SplashShowOnlyFirstTime" value="true"/>
  <preference name="xwalkZOrderOnTop" value="true"/>
  <preference name="loadUrlTimeoutValue" value="700000"/>
  <feature name="StatusBar">
    <param name="ios-package" onload="true" value="CDVStatusBar"/>
  </feature>
  <platform name="android">
    <allow-intent href="market:*"/>
    <icon src="resources/android/icon/drawable-ldpi-icon.png" density="ldpi"/>
    <icon src="resources/android/icon/drawable-mdpi-icon.png" density="mdpi"/>
    <icon src="resources/android/icon/drawable-hdpi-icon.png" density="hdpi"/>
    <icon src="resources/android/icon/drawable-xhdpi-icon.png" density="xhdpi"/>
    <icon src="resources/android/icon/drawable-xxhdpi-icon.png" density="xxhdpi"/>
    <icon src="resources/android/icon/drawable-xxxhdpi-icon.png" density="xxxhdpi"/>
    <splash src="resources/android/splash/drawable-land-ldpi-screen.png" density="land-ldpi"/>
    <splash src="resources/android/splash/drawable-land-mdpi-screen.png" density="land-mdpi"/>
    <splash src="resources/android/splash/drawable-land-hdpi-screen.png" density="land-hdpi"/>
    <splash src="resources/android/splash/drawable-land-xhdpi-screen.png" density="land-xhdpi"/>
    <splash src="resources/android/splash/drawable-land-xxhdpi-screen.png" density="land-xxhdpi"/>
    <splash src="resources/android/splash/drawable-land-xxxhdpi-screen.png" density="land-xxxhdpi"/>
    <splash src="resources/android/splash/drawable-port-ldpi-screen.png" density="port-ldpi"/>
    <splash src="resources/android/splash/drawable-port-mdpi-screen.png" density="port-mdpi"/>
    <splash src="resources/android/splash/drawable-port-hdpi-screen.png" density="port-hdpi"/>
    <splash src="resources/android/splash/drawable-port-xhdpi-screen.png" density="port-xhdpi"/>
    <splash src="resources/android/splash/drawable-port-xxhdpi-screen.png" density="port-xxhdpi"/>
    <splash src="resources/android/splash/drawable-port-xxxhdpi-screen.png" density="port-xxxhdpi"/>
  </platform>
  <platform name="ios">
    <allow-intent href="itms:*"/>
    <allow-intent href="itms-apps:*"/>
    <icon src="resources/ios/icon/icon.png" width="57" height="57"/>
    <icon src="resources/ios/icon/icon@2x.png" width="114" height="114"/>
    <icon src="resources/ios/icon/icon-40.png" width="40" height="40"/>
    <icon src="resources/ios/icon/icon-40@2x.png" width="80" height="80"/>
    <icon src="resources/ios/icon/icon-40@3x.png" width="120" height="120"/>
    <icon src="resources/ios/icon/icon-50.png" width="50" height="50"/>
    <icon src="resources/ios/icon/icon-50@2x.png" width="100" height="100"/>
    <icon src="resources/ios/icon/icon-60.png" width="60" height="60"/>
    <icon src="resources/ios/icon/icon-60@2x.png" width="120" height="120"/>
    <icon src="resources/ios/icon/icon-60@3x.png" width="180" height="180"/>
    <icon src="resources/ios/icon/icon-72.png" width="72" height="72"/>
    <icon src="resources/ios/icon/icon-72@2x.png" width="144" height="144"/>
    <icon src="resources/ios/icon/icon-76.png" width="76" height="76"/>
    <icon src="resources/ios/icon/icon-76@2x.png" width="152" height="152"/>
    <icon src="resources/ios/icon/icon-83.5@2x.png" width="167" height="167"/>
    <icon src="resources/ios/icon/icon-small.png" width="29" height="29"/>
    <icon src="resources/ios/icon/icon-small@2x.png" width="58" height="58"/>
    <icon src="resources/ios/icon/icon-small@3x.png" width="87" height="87"/>
    <splash src="resources/ios/splash/Default-568h@2x~iphone.png" width="640" height="1136"/>
    <splash src="resources/ios/splash/Default-667h.png" width="750" height="1334"/>
    <splash src="resources/ios/splash/Default-736h.png" width="1242" height="2208"/>
    <splash src="resources/ios/splash/Default-Landscape-736h.png" width="2208" height="1242"/>
    <splash src="resources/ios/splash/Default-Landscape@2x~ipad.png" width="2048" height="1536"/>
    <splash src="resources/ios/splash/Default-Landscape~ipad.png" width="1024" height="768"/>
    <splash src="resources/ios/splash/Default-Portrait@2x~ipad.png" width="1536" height="2048"/>
    <splash src="resources/ios/splash/Default-Portrait~ipad.png" width="768" height="1024"/>
    <splash src="resources/ios/splash/Default@2x~iphone.png" width="640" height="960"/>
    <splash src="resources/ios/splash/Default~iphone.png" width="320" height="480"/>
  </platform>
  <platform name="wp8">
    <icon src="resources/wp8/icon/ApplicationIcon.png" width="99" height="99"/>
    <icon src="resources/wp8/icon/Background.png" width="159" height="159"/>
    <splash src="resources/wp8/splash/SplashScreenImage.png" width="768" height="1280"/>
  </platform>
  <icon src="resources/android/icon/drawable-xhdpi-icon.png"/>
  <plugin name="cordova-plugin-badge" spec="~0.7.4"/>
  <plugin name="cordova.plugins.diagnostic" spec="~3.1.7"/>
  <plugin name="cordova-plugin-whitelist" spec="~1.3.2"/>
  <plugin name="cordova-plugin-app-version" spec="~0.1.9"/>
  <plugin name="onesignal-cordova-plugin" spec="~2.0.11"/>
</widget>

index.html:

..
  <meta http-equiv="Content-Security-Policy" content="default-src gap://ready file://* *; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src 'self' 'unsafe-inline' *">
...

package.json

{
  "name": "ionic-hello-world",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": {
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve"
  },
  "dependencies": {
    "@angular/common": "2.4.8",
    "@angular/compiler": "2.4.8",
    "@angular/compiler-cli": "2.4.8",
    "@angular/core": "2.4.8",
    "@angular/forms": "2.4.8",
    "@angular/http": "2.4.8",
    "@angular/platform-browser": "2.4.8",
    "@angular/platform-browser-dynamic": "2.4.8",
    "@angular/platform-server": "2.4.8",
    "@ionic/storage": "2.0.0",
    "angular2-moment": "^1.1.0",
    "gl-ionic2-env-configuration": "0.0.18",
    "ionic-angular": "2.2.0",
    "ionic-native": "2.4.1",
    "ionicons": "3.0.0",
    "rxjs": "5.0.1",
    "sw-toolbox": "3.4.0",
    "zone.js": "0.7.2"
  },
  "devDependencies": {
    "@ionic/app-scripts": "^1.2.5",
    "typescript": "2.0.9"
  },
  "cordovaPlugins": [
    "cordova-plugin-whitelist",
    "cordova-plugin-console",
    "cordova-plugin-statusbar",
    "cordova-plugin-device",
    "cordova-plugin-splashscreen",
    "cordova-plugin-app-version",
    "cordova.plugins.diagnostic",
    "cordova-plugin-badge",
    "onesignal-cordova-plugin",
    "ionic-plugin-keyboard"
  ],
  "cordovaPlatforms": [],
  "description": "mobmedmobile: An Ionic project"
}

#2

package.json could be useful, too.

What is happening?


#3

I just added package.json

...
  constructor(
    public platform: Platform,
    public userSession: UserSession,
    public httpClientService: HttpClientService,
    public notificationService: NotificationService,
    public localStorage: Storage,
    public loadingController: LoadingController,
    private envConfiguration: EnvConfigurationProvider<AppEnvConfiguration>,
    public events: Events
  ) {
    this.onesignalKey = envConfiguration.getConfig().onesignalKey;
    this.onesignalProjectNumber = envConfiguration.getConfig().onesignalProjectNumber;
    this.initializeVersion();
    this.initializeApp();
    this.initPush();
  }

  initializeVersion() {
    if(this.platform.is('cordova')) {
      AppVersion.getVersionNumber().then((version) => {
        this.httpClientService.addHeader('APP_VERSION', version);
      });
    }
  }

  initPush() {
    if(this.platform.is('cordova')) {
      OneSignal.startInit(this.onesignalKey, this.onesignalProjectNumber);
      OneSignal.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification);

      OneSignal.handleNotificationReceived().subscribe(() => {
       ...
      });

      OneSignal.handleNotificationOpened().subscribe((jsonData) => {
        ...
      });

      OneSignal.endInit();
    }
  }

Because of the first plugin cordova-plugin-app-version in nitializeVersion() the returned version of is nil:

Second plugin causes stuck app at beginning when I comment line this.initPush(); the rest of the application will work correctly.

Why in emulation mode works fine?
It may be helpful to note that on Android application also works fine…


#4

This list in package.json is missing some of your plugins. Normally they should be in there, too.
(Don’t ask my why this is in so many places…)


#5

Thanks @Sujan12 for reply
I updated package.json in project and here,
I re-added platform ios
Unfortunately, the result is the same on emulate work on real device not …
I completely do not understand why this is happening what else can be responsible for it?

Here is log when first time running emulate:

** BUILD SUCCEEDED **


No target specified for emulator. Deploying to iPhone-SE, 10.3 simulator


logPath: /Users/m1l05z/Desktop/projects/mobmedmobile/platforms/ios/cordova/console.log

[10:33:34]  console.warn: Native: tried calling AppVersion.getVersionNumber, but the AppVersion plugin is not installed. 
[10:33:34]  console.warn: Install the AppVersion plugin: 'ionic plugin add cordova-plugin-app-version' 
[10:33:34]  console.warn: Native: tried calling OneSignal.setLogLevel, but the OneSignal plugin is not installed. 
[10:33:34]  console.warn: Install the OneSignal plugin: 'ionic plugin add onesignal-cordova-plugin' 
[10:33:34]  console.warn: Native: tried calling OneSignal.startInit, but the OneSignal plugin is not installed. 
[10:33:34]  console.warn: Install the OneSignal plugin: 'ionic plugin add onesignal-cordova-plugin' 
[10:33:34]  console.warn: Native: tried calling OneSignal.inFocusDisplaying, but the OneSignal plugin is not installed. 
[10:33:34]  console.warn: Install the OneSignal plugin: 'ionic plugin add onesignal-cordova-plugin' 
[10:33:34]  console.warn: Native: tried calling OneSignal.handleNotificationReceived, but the OneSignal plugin is not 
            installed. 
[10:33:34]  console.warn: Install the OneSignal plugin: 'ionic plugin add onesignal-cordova-plugin' 
[10:33:34]  console.error: EXCEPTION: plugin_not_installed 
[10:33:34]  console.warn: Native: tried calling AppVersion.getVersionNumber, but the AppVersion plugin is not installed. 
[10:33:34]  console.warn: Install the AppVersion plugin: 'ionic plugin add cordova-plugin-app-version' 
[10:33:34]  console.warn: Native: tried calling OneSignal.setLogLevel, but the OneSignal plugin is not installed. 
[10:33:34]  console.warn: Install the OneSignal plugin: 'ionic plugin add onesignal-cordova-plugin' 
[10:33:34]  console.warn: Native: tried calling OneSignal.startInit, but the OneSignal plugin is not installed. 
[10:33:34]  console.warn: Install the OneSignal plugin: 'ionic plugin add onesignal-cordova-plugin' 
[10:33:34]  console.warn: Native: tried calling OneSignal.inFocusDisplaying, but the OneSignal plugin is not installed. 
[10:33:34]  console.warn: Install the OneSignal plugin: 'ionic plugin add onesignal-cordova-plugin' 
[10:33:34]  console.warn: Native: tried calling OneSignal.handleNotificationReceived, but the OneSignal plugin is not 
            installed. 
[10:33:34]  console.warn: Install the OneSignal plugin: 'ionic plugin add onesignal-cordova-plugin' 
[10:33:34]  console.error: EXCEPTION: plugin_not_installed 
[10:33:34]  console.error: EXCEPTION: Uncaught (in promise): plugin_not_installed 
[10:33:34]  console.error: ORIGINAL STACKTRACE: 
[10:33:34]  console.error: v@http://10.20.20.138:8100/build/polyfills.js:3:4869 
            s@http://10.20.20.138:8100/build/polyfills.js:3:4298 s@http://10.20.20.138:8100/build/polyfills.js:3:4113 
            http://10.20.20.138:8100/build/polyfills.js:3:4653 
            invokeTask@http://10.20.20.138:8100/build/polyfills.js:3:10289 
            onInvokeTask@http://10.20.20.138:8100/build/main.js:45476:47 
            invokeTask@http://10.20.20.138:8100/build/polyfills.js:3:10232 
            runTask@http://10.20.20.138:8100/build/polyfills.js:3:7647 
            i@http://10.20.20.138:8100/build/polyfills.js:3:3714 
            invoke@http://10.20.20.138:8100/build/polyfills.js:3:11438 
[10:33:34]  console.error: Unhandled Promise rejection: plugin_not_installed ; Zone: <root> ; Task: Promise.then ; 
            Value: plugin_not_installed null 
[10:33:34]  console.error: EXCEPTION: Uncaught (in promise): plugin_not_installed 
[10:33:34]  console.error: ORIGINAL STACKTRACE: 
[10:33:34]  console.error: v@http://10.20.20.138:8100/build/polyfills.js:3:4869 
            s@http://10.20.20.138:8100/build/polyfills.js:3:4298 s@http://10.20.20.138:8100/build/polyfills.js:3:4113 
            http://10.20.20.138:8100/build/polyfills.js:3:4653 
            invokeTask@http://10.20.20.138:8100/build/polyfills.js:3:10289 
            onInvokeTask@http://10.20.20.138:8100/build/main.js:45476:47 
            invokeTask@http://10.20.20.138:8100/build/polyfills.js:3:10232 
            runTask@http://10.20.20.138:8100/build/polyfills.js:3:7647 
            i@http://10.20.20.138:8100/build/polyfills.js:3:3714 
            invoke@http://10.20.20.138:8100/build/polyfills.js:3:11438 
[10:33:34]  error opening ws message: {"category":"console","type":"log","data":["DEVICE READY FIRED AFTER",2216,"ms"]} 

When I run once again it works fine…
Updated config.xml because I noticed when running emulate it added two lines to file

  <content src="http://10.20.20.138:8100" original-src="index.html"/>
  <allow-navigation href="http://10.20.20.138:8100"/>

SOLVED

Cut me off, it turned out to be the fault of using these two plugins outside platform ready :triumph: