我正在尝试在iOS模拟器上运行NativeScript-Application。由于iTunes希望由Xcode 9.0或更高版本发布应用程序,因此我不得不从具有Xcode 7.3的NativeScript iOS v3.1升级(我的应用程序运行得很好)到具有Xcode 9.0的NativeScript iOS v4.2。现在可悲的是,我无法在任何设备上执行我的应用程序。它从头开始,我看到加载屏幕,然后遇到此错误:
CONSOLE ERROR file:///app/tns_modules/zone.js/dist/zone-node.js:419:27: Unhandled Promise rejection: UIScreen.mainScreen is not a function. (In 'UIScreen.mainScreen()', 'UIScreen.mainScreen' is an instance of UIScreen) ; Zone: angular ; Task: Promise.then ; Value: TypeError: UIScreen.mainScreen is not a function. (In 'UIScreen.mainScreen()', 'UIScreen.mainScreen' is an instance of UIScreen)
CONSOLE ERROR file:///app/tns_modules/zone.js/dist/zone-node.js:421:23: Error: Uncaught (in promise): TypeError: UIScreen.mainScreen is not a function. (In 'UIScreen.mainScreen()', 'UIScreen.mainScreen' is an instance of UIScreen)
当我使用NativeScript-iOS 3.1.0返回Xcode 7.3时,它再次正常运行。我不知道该如何解决这个问题。
我已经看到一些与UIScreen.MainScreen错误相关的问题(例如here),但是它们似乎与iOS原生相关,因此我无法从NativeScript中受到影响(至少我不知道该怎么做)
现在这是我的配置文件:
package.json:
{ //...
"tns-ios": {
"version": "4.2.0"
}
},
"dependencies": {
"@angular/common": "2.0.0-rc.4",
"@angular/compiler": "2.0.0-rc.4",
"@angular/core": "2.0.0-rc.4",
"@angular/http": "2.0.0-rc.4",
"@angular/platform-browser": "2.0.0-rc.4",
"@angular/platform-browser-dynamic": "2.0.0-rc.4",
"@angular/platform-server": "2.0.0-rc.4",
"@angular/router": "3.0.0-beta.2",
"nativescript-angular": "0.3.1-2016-08-04-787",
"nativescript-calendar": "1.1.2",
"nativescript-drop-down": "1.3.2",
"nativescript-fresco": "1.0.6",
"nativescript-ng2-translate": "1.1.1",
"nativescript-social-share": "1.3.0",
"nativescript-telerik-ui": "1.3.1",
"ng2-translate": "2.2.2",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.6",
"tns-core-modules": "^2.4.4",
"typescript": "^1.8.10",
"url": "0.10.3",
"zone.js": "0.6.12"
},
"devDependencies": {
"babel-traverse": "6.10.4",
"babel-types": "6.10.2",
"babylon": "6.8.1",
"filewalker": "0.1.3",
"lazy": "1.0.11",
"nativescript-dev-typescript": "0.3.2",
"nativescript-dev-webpack": "0.0.20",
"typescript": "1.8.10"
}
}
build.xcconfig:
CODE_SIGN_IDENTITY = iPhone Developer;
DEVELOPMENT_TEAM = %Number%;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
IPHONEOS_DEPLOYMENT_TARGET = 8.1;
info.plist:
<?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>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>%App_Name%</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>2.0.9</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>2.0.9.4</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIRequiresFullScreen</key>
<true/>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>iPhoneOS</string>
</array>
<key>NSCalendarsUsageDescription</key>
<string>my app needs access to the calendar to create new entries</string>
<key>Minimum </key>
<string></string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>localhost</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
<key>%ip%</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
</dict>
</plist>
答案 0 :(得分:1)
问题是您的tns-core-modules
是较旧的版本(大约2年),并且正在使用已经弃用的iOS API,其中mainScreen
是一个函数(现在是属性)。当旧tns-core-modules
中的代码正在使用旧API时,您仅更新了与新iOS API一起使用的tns-ios运行时。用两个词-将不起作用,您将必须更新tns-core-modules
和nativescript-angular
+所有相关的依赖项。您可能还需要在此处和此处更新代码隐藏文件。
可以找到here的package/json
依赖项的升级说明
从2.x.x here迁移时需要考虑的重大更改
另请参见tns-core-modules
here
最后,here可以找到nativescript-angular
的CHANGELOG