我正在使用以下代码......
openPhoneDialler(mobile) {
let url = 'tel:' + mobile;
Linking.canOpenURL(url).then(supported => {
if (!supported) {
throw 'Cant open phone dialler';
} else {
return Linking.openURL(url);
}
}).catch(err =>
Alert.alert('Error','Error occurred',[{text: 'OK', onPress: () => {}}])
);
}
我在没有SIM卡功能的iPad上测试(仅限Wifi),canOpenURL得到解决,并且调用Linking.openURL(url),显示带有手机号码的警报和两个选项'取消'和'呼叫' 。当我按下“呼叫”时,警报会关闭,没有任何事情发生,因为它只是Wifi iPad。
但是当我按下“取消”时,应用程序会因以下错误屏幕崩溃
JSON value '{
code = EUNSPECIFIED;
domain = RCTErrorDomain;
framesToPop = 1;
nativeStackIOS = (
"0 workforce_mobile 0x00000001000d4d00 RCTJSErrorFromCodeMessageAndNSError + 152",
"1 workforce_mobile 0x0000000100053e4c __41-[RCTModuleMethod processMethodSignature]_block_invoke_2.224 + 192",
"2 workforce_mobile 0x000000010015e2f0 -[RCTLinkingManager openURL:resolve:reject:] + 352",
"3 CoreFoundation 0x000000018164ce80 <redacted> + 144",
"4 CoreFoundation 0x00000001815422b4 <redacted> + 292",
"5 CoreFoundation 0x0000000181546e7c <redacted> + 60",
"6 workforce_mobile 0x0000000100055098 -[RCTModuleMethod invokeWithBridge:module:arguments:] + 1704",
"7 workforce_mobile 0x00000001000aea54 -[RCTBatchedBridge callNativeModule:method:params:] + 568",
"8 workforce_mobile 0x00000001000addf4 __33-[RCTBatchedBridge handleBuffer:]_block_invoke.477 + 1276",
"9 libdispatch.dylib 0x00000001804fe9e0 <redacted> + 24",
"10 libdispatch.dylib 0x00000001804fe9a0 <redacted> + 16",
"11 libdispatch.dylib 0x000000018050cad4 <redacted> + 928",
"12 libdispatch.dylib 0x00000001805022cc <redacted> + 884",
"13 libdispatch.dylib 0x000000018050ea50 <redacted> + 540",
"14 libdispatch.dylib 0x000000018050e7d0 <redacted> + 124",
"15 libsystem_pthread.dylib 0x00000001807071d0 _pthread_wqthread + 1096",
"16 libsystem_pthread.dylib 0x0000000180706d7c start_wqthread + 4"
);
userInfo = "<null>";
}' of type NSDictionary cannot be converted to NSString
注意:如果您在没有任何按下的情况下将警报打开大约10秒钟,也会发生同样的崩溃。
测试:iPad(仅限Wifi和物理设备)操作系统版本10.3.1
这是React-Native Linking Api中的错误还是上述代码中的错误。
答案 0 :(得分:-1)
Linking.openUrl
返回一个promise对象。按取消按钮,您的承诺将被拒绝。只需添加一个捕获来吞下被拒绝的承诺。
Linking.openUrl().catch(() => null)
以下是有关该文档的文档:
https://facebook.github.io/react-native/docs/linking.html#openurl