我最近開始在使用react-native
構建的iOS移動應用程序中出現此錯誤(詳細錯誤如下)。只有當我嘗試通過使用要使用靜態綁定進行加載的Option 2
在手機上運行應用程序時,纔會發生這種情況。我曾嘗試:NSInternalInconsistencyException:在未實現loadSourceForBridge時,bundleURL必須爲非零
- 清潔並在Xcode 重建
- 復位高速緩存和運行反應打包
- 卸載手機
- 從Windows背景的上的應用程序,我也試圖重新啓動我的機器
錯誤在Xcode
2016-08-04 09:34:37.611 GalarmApp[367:165469] *** Assertion failure in
-[RCTBatchedBridge loadSource:](), /Users/abc/Projects/GalarmApp/node_modules/react-native/React/Base/RCTBatchedBridge.m:180 2016-08-04 09:34:37.613 GalarmApp[367:165469] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'bundleURL must be non-nil when not implementing loadSourceForBridge'
*** First throw call stack: (0x182b32db0 0x182197f80 0x182b32c80 0x1834b81c0 0x1000af788 0x1000adefc 0x1000adca4 0x1000e73d8 0x1000e7368 0x1000e6700 0x1000e643c 0x10005a254 0x10003cebc 0x10003c214 0x10003966c 0x100039b18 0x187d069c0 0x187f36184 0x187f3a5f0 0x187f37764 0x1844d37ac 0x1844d3618 0x1844d39c8 0x182ae909c 0x182ae8b30 0x182ae6830 0x182a10c50 0x187cff94c 0x187cfa088 0x10003bee0 0x1825ae8b8) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)
我可以看到這個問題在代碼中打印爲here,但我在初始iOS開發中最好是初學者,不知道如何解決這個問題。
請幫我解決這個問題。謝謝!在AppDelegate.swift
代碼文件
/**
* Loading JavaScript code - uncomment the one you want.
*
* OPTION 1
* Load from development server. Start the server from the repository root:
*
* $ npm start
*
* To run on device, change `localhost` to the IP address of your computer
* (you can get this by typing `ifconfig` into the terminal and selecting the
* `inet` value under `en0:`) and make sure your computer and iOS device are
* on the same Wi-Fi network.
*/
// let jsCodeLocation = NSURL(string: "http://localhost:8081/index.ios.bundle?platform=ios&dev=true")
/**
* OPTION 2
* Load from pre-bundled file on disk. The static bundle is automatically
* generated by "Bundle React Native code and images" build step.
*/
let jsCodeLocation = NSBundle.mainBundle().URLForResource("main", withExtension: "jsbundle")
正如你所看到的,我已經註釋掉Option 1
和註釋掉了「期權2`。我已經在設備上以這種方式運行相同的應用程序,如100次。我沒有對代碼做任何改變,但突然間我開始看到上面的錯誤。
您應該在AppDelegate.m中添加包URL,如果您在真實設備上運行應用程序。 – Sriraman
@Sriraman包URL必須存在於AppDelegate文件中。我沒有對AppDelegate中的代碼進行任何更改,並且我多次在設備上運行相同的代碼。我懷疑它與打包程序有關,它不會創建所需的js文件。 –
請參閱此問題上接受的答案以獲取更多信息http://stackoverflow.com/questions/38780325/running-react-native-app-on-ios-device-using-offline-bundle/38780622#38780622。 –