Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App crashes due to main interface NSMainNibFile~ipad #90

Closed
Ritzlgrmft opened this issue Nov 20, 2016 · 16 comments
Closed

App crashes due to main interface NSMainNibFile~ipad #90

Ritzlgrmft opened this issue Nov 20, 2016 · 16 comments

Comments

@Ritzlgrmft
Copy link
Contributor

I am using the plugin for using different orientation settings for iPhone and iPad:

<plugin name="cordova-custom-config" spec="~3.0.14" />
<platform name="ios">
	<!-- Set orientation on iPhone -->
	<config-file platform="ios" target="*-Info.plist" parent="UISupportedInterfaceOrientations">
		<array>
			<string>UIInterfaceOrientationPortrait</string>
		</array>
	</config-file>

	<!-- Set orientation on iPad -->
	<config-file platform="ios" target="*-Info.plist" parent="UISupportedInterfaceOrientations~ipad">
		<array>
			<string>UIInterfaceOrientationPortrait</string>
			<string>UIInterfaceOrientationPortraitUpsideDown</string>
			<string>UIInterfaceOrientationLandscapeLeft</string>
			<string>UIInterfaceOrientationLandscapeRight</string>
		</array>
	</config-file>
</platform>

(more or less the same as in your example)

After cordova prepare, on the first view everything looks fine in Xcode. But... the main interface has now the value NSMainNibFile~ipad - for iPhone as well as for iPad. And when I try to start the app on iPhone, I get an exception:

2016-11-20 19:43:11.608802 MyApp[6999:3563272] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </var/containers/Bundle/Application/CB7A3A0A-AEDD-488E-B166-99D5FCD4902A/MyApp.app> (loaded)' with name 'NSMainNibFile~ipad''
*** First throw call stack:
(0x1928f61c0 0x19133055c 0x1928f6108 0x198c5259c 0x198c54d38 0x1989da6ec 0x1987c2d7c 0x1989d94a8 0x1989ede60 0x1989d65ac 0x19449d8bc 0x19449d728 0x19449dad0 0x1928a4278 0x1928a3bc0 0x1928a17c0 0x1927d0048 0x1987bc2b0 0x1987b7034 0x1000f132c 0x1917b45b8)
libc++abi.dylib: terminating with uncaught exception of type NSException 

When I clear the field for main interface manually, everything works fine. But this is not, what I want to do.

I am using:

Cordova CLI: 6.4.0 
OS: macOS Sierra
Node Version: v4.6.0
Xcode version: Xcode 8.1 Build version 8B62
iOS: 10.1.1

Is there something, I am doing wrong? Or is there a hidden "feature" in the plugin?

@dpa99c
Copy link
Owner

dpa99c commented Nov 20, 2016

Please try building the example project to confirm you can reproduce this issue in isolation from other plugins and modules.

@Ritzlgrmft
Copy link
Contributor Author

I checked with your example project, and indeed, it worked. But I assume, this was pure luck:

In the backup of *-Info.plist, I see

<key>NSMainNibFile</key>
<string/>
<key>NSMainNibFile~ipad</key>
<string/>

But when I add some logging at the beginning of updateIosPlist in applyCustomConfig.js:

tempInfoPlist = plist.build(infoPlist);
logger.verbose(tempInfoPlist);

Already there, the plist content is corrupt. The empty strings are gone:

<key>NSMainNibFile</key>
<key>NSMainNibFile~ipad</key>

This happens, since plist is not working symmetrically.

plist.build(plist.parse("<plist><dict><key>NSMainNibFile</key><string></string></dict></plist>”))

produces

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>NSMainNibFile</key>
  </dict>
</plist>

Therefore the string value is gone. See also TooTallNate/plist.js#79.

I tried to fix it by explicitly setting the values:

<config-file platform="ios" target="*-Info.plist" parent="NSMainNibFile">
  <string></string>
</config-file>
<config-file platform="ios" target="*-Info.plist" parent="NSMainNibFile~ipad">
  <string></string>
</config-file> 

But this did not work. Finally I replaced the line

infoPlist[key] = configPlistObj[key];

with

var value = configPlistObj[key];
if (!value && item.data.tag === "string") {
  value = "";
}
infoPlist[key] = value;

Now everything is fine. It would be great if you could add this fix to your plugin.

@renaudpawlak
Copy link

I have a similar issue on my project. Whenever I use config-file for iOS, the original Cordova-generated:

    <key>NSMainNibFile</key>
    <string></string>
    <key>NSMainNibFile~ipad</key>
    <string></string>

gets converted to:

    <key>NSMainNibFile</key>
    <key>NSMainNibFile~ipad</key>

which makes the app crash!

@dpa99c
Copy link
Owner

dpa99c commented Nov 26, 2016

Should be fixed in cordova-custom-config@3.1.0.
If still an issue, let me know, and I'll reopen.

@dpa99c dpa99c closed this as completed Nov 26, 2016
@noderat
Copy link

noderat commented Feb 17, 2017

@dpa99c This is still occurring on 3.1.2 for me with XCode 8.2.1 exactly as detailed earlier in this issue.

@WuglyakBolgoink
Copy link

WuglyakBolgoink commented Apr 7, 2017

in v3.1.3 NOT fixed!!! or you do too much breaking changes in updates :(

<platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />

        <!-- Set deploy target SDKs for release and debug builds -->
        <preference name="ios-XCBuildConfiguration-IPHONEOS_DEPLOYMENT_TARGET" value="9.0" buildType="debug" />
        <preference name="ios-XCBuildConfiguration-IPHONEOS_DEPLOYMENT_TARGET" value="9.0" buildType="release" />

        <config-file platform="ios" parent="NSContactsUsageDescription" target="*-Info.plist">
            <string>$(PRODUCT_NAME) Allow use Contact</string>
        </config-file>
        <config-file platform="ios" parent="NSPhotoLibraryUsageDescription" target="*-Info.plist">
            <string>$(PRODUCT_NAME) Allow use PhotoLibrary</string>
        </config-file>
        <config-file platform="ios" parent="NSCameraUsageDescription" target="*-Info.plist">
            <string>$(PRODUCT_NAME) Allow use Camera</string>
        </config-file>
        <config-file platform="ios" parent="ITSAppUsesNonExemptEncryption" target="*-Info.plist">
            <false />
        </config-file>

    </platform>
[366:72738] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
 reason: 'Could not load NIB in bundle: 
'NSBundle </var/containers/Bundle/Application/1hasdjfhsakdfhls/my.app> (loaded)' 
with name 'NSMainNibFile~ipad''

@dpa99c
Copy link
Owner

dpa99c commented Apr 7, 2017

@WuglyakBolgoink

in v3.1.3 NOT fixed!!!

I tried using the exact config you have posted in an isolated test case and it works fine with cordova-custom-config@3.1.3 - Xcode opens the project, builds and runs without crashing - see this screencast and the resulting Cordova project.

Please post exact steps to reproduce or an equivalent Cordova project which illustrates the issue.

or you do too much breaking changes in updates

You can see this is not the case if you look at the commit history

@WuglyakBolgoink
Copy link

WuglyakBolgoink commented Apr 7, 2017

@dpa99c

  • cordova platform rm ios
  • cordova plugins rm cordova-custom-config
  • cordova plugins add cordova-custom-config
  • cordova platform add ios
  • cordova build ios --release

NSMainNibFile~ipad as default MAIN NIB -> I created test project with cordova.. this line is empty!!!

PS: in backup file NSContactsUsageDescription is always empty!? WTF?
I removed from *.Info.plist NSMainNibFile~ipad, only after I can start my App...

@dpa99c
Copy link
Owner

dpa99c commented Apr 7, 2017

@WuglyakBolgoink Those steps work fine for me: release builds OK and it runs OK: screencast.

Using cordova@6.5.0 and cordova-ios@4.3.1.

@WuglyakBolgoink
Copy link

WuglyakBolgoink commented Apr 7, 2017

Hallo @dpa99c ,

I think , something wrong with my dev environment today (I have next 2 week vacation) and I didn't have much time to fix this issue. I try to do clean project with my cordova.xml config file after vacation.

@jonathankau
Copy link

jonathankau commented Apr 9, 2017

It looks like the most recent version of plist@2.0.1 caused these issues to re-emerge. Reverting back to plist@2.0.0 fixed the issue for us. TooTallNate/plist.js#79

@dpa99c
Copy link
Owner

dpa99c commented Apr 9, 2017

@jonathankau Thanks for the info, that maybe explains why I couldn't reproduce it but @WuglyakBolgoink can. I will investigate. If this is the case, I will fix the version to plist@2.0.0 for now in package.json.

@dpa99c dpa99c added investigate and removed bug labels Apr 9, 2017
@dpa99c dpa99c reopened this Apr 9, 2017
@dpa99c
Copy link
Owner

dpa99c commented Apr 11, 2017

I'm able to reproduce this issue if I explicitly force the version to plist@2.0.1.

However, this plugin has for sometime pinned the version to ^1.2.0. so I'm not able to reproduce it by installing the latest plugin version (which in turn installs plist@1.2.0) - only by manually hacking the project to force the version to plist@2.0.1.

Since npm@3 uses a flattened dependency tree, is it possible that if another plugin/dependency requests plist@2.0.1, that this plugin is being served plist@2.0.1 instead of plist@1.2.0?
From the npm@3 documentation, I don't think this should be the case.

The following console output shows my node_modules structure after installing the plugin:

console output

cordova-custom-config-example$ cordova plugin rm cordova-custom-config
cordova-custom-config: Skipping auto-restore of config file backup(s)
Uninstalling cordova-custom-config from ios
Removing "cordova-custom-config"
cordova-custom-config-example$ rm -Rf node_modules/
cordova-custom-config-example$ cordova plugin add cordova-custom-config@latest
Fetching plugin "cordova-custom-config@latest" via npm
Installing "cordova-custom-config" for ios
cordova-custom-config: npm dependencies missing - installing
cordova-custom-config: Installed npm dependencies
cordova-custom-config-example$ npm list
cordova-custom-config-example@3.0.0 /Users/dave/Documents/projects/cordova-custom-config-example
├─┬ cordova-custom-config@3.1.3
│ ├── colors@1.1.2
│ ├─┬ elementtree@0.1.7
│ │ └── sax@1.1.4
│ ├── lodash@4.17.4
│ ├─┬ plist@1.2.0
│ │ ├── base64-js@0.0.8
│ │ ├── util-deprecate@1.0.2
│ │ ├─┬ xmlbuilder@4.0.0
│ │ │ └── lodash@3.10.1
│ │ └── xmldom@0.1.27
│ ├─┬ shelljs@0.7.7
│ │ ├─┬ glob@7.1.1
│ │ │ ├── fs.realpath@1.0.0
│ │ │ ├─┬ inflight@1.0.6
│ │ │ │ └── wrappy@1.0.2
│ │ │ ├── inherits@2.0.3
│ │ │ ├─┬ minimatch@3.0.3
│ │ │ │ └─┬ brace-expansion@1.1.7
│ │ │ │   ├── balanced-match@0.4.2
│ │ │ │   └── concat-map@0.0.1
│ │ │ ├── once@1.4.0
│ │ │ └── path-is-absolute@1.0.1
│ │ ├── interpret@1.0.2
│ │ └─┬ rechoir@0.6.2
│ │   └─┬ resolve@1.3.2
│ │     └── path-parse@1.0.5
│ ├── tostr@0.1.0
│ └─┬ xcode@0.8.9
│   ├── node-uuid@1.4.7
│   ├── pegjs@0.9.0
│   └─┬ simple-plist@0.1.4
│     ├─┬ bplist-creator@0.0.4
│     │ └── stream-buffers@0.2.6
│     └── bplist-parser@0.0.6
├── UNMET DEPENDENCY jasmine@^2.5.2
└── UNMET DEPENDENCY jshint@^2.6.0

npm ERR! missing: jshint@^2.6.0, required by cordova-custom-config-example@3.0.0
npm ERR! missing: jasmine@^2.5.2, required by cordova-custom-config-example@3.0.0

If someone who is encountering this issue could post the output from npm list from the project, maybe I can get some insight into why this plugin may be getting served the buggy plist@2.0.1 instead of plist@1.2.0 as it's requesting.

@davidefavia
Copy link

Hi,
I encountered the same issue. I noticed @dpa99c has xcode@0.8.9 as dependency, whilst I had xcode@^0.9.1 (which imports plist@2.0.1). Downgrade to oldest version pulls in plist@1.2.0 and now the .plist file is no more corrupted. I think @dpa99c is right in his comment.

@dpa99c
Copy link
Owner

dpa99c commented Apr 17, 2017

Going to close this since there's nothing more that can be done by this plugin to resolve this, i.e. it is pinning plist@^1.2.0 in its package.json (which should not resolve to plist@2) but it cannot prevent this being overridden to a later (buggy) plist@2 version by another sibling module.

@drbeermann
Copy link

drbeermann commented Oct 4, 2017

This seems to be an issue with the newest version of xcode.

└─┬ xcode@0.9.3
  ├── pegjs@0.10.0
  ├─┬ simple-plist@0.2.1
  │ ├─┬ bplist-creator@0.0.7
  │ │ └── stream-buffers@2.2.0
  │ ├─┬ bplist-parser@0.1.1
  │ │ └── big-integer@1.6.19
  │ └─┬ plist@2.0.1
  │   ├── base64-js@1.1.2
  │   ├── xmlbuilder@8.2.2
  │   └── xmldom@0.1.27 deduped
  └── uuid@3.0.1

For what it's worth, this does seem to fix it for me:

<config-file platform="ios" target="*-Info.plist" parent="NSMainNibFile">
  <string/>
</config-file>
<config-file platform="ios" target="*-Info.plist" parent="NSMainNibFile~ipad">
  <string/>
</config-file>

dpa99c added a commit that referenced this issue Dec 18, 2017
Set plist dependency to use fork which fixes bug causing #136 and #90.
Set xcode to @1.0.0 which is published from the new apache/cordova repo.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants