我正在实施反应原生应用程序中的深层链接,点击应用程序A中的查看以打开应用程序B.在直接从其他应用程序调用URL之前,我想测试它是否正常工作,
所以对于android来说它有效。我只是将启动选项设置为URL,它在控制台中显示了URL的值。
但是在iPhone中,如果我在Safari浏览器中写入URL( testlink:// ),则显示“safari无法打开页面,因为地址无效”。
我遵循设置深层链接的步骤:
#import <React/RCTLinkingManager.h>
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [RCTLinkingManager application:application openURL:url
sourceApplication:sourceApplication annotation:annotation];
}
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler
{
return [RCTLinkingManager application:application
continueUserActivity:userActivity
restorationHandler:restorationHandler];
}
&#13;
在XCode中的info.plist中添加了一个键。
网址类型 - &gt;项目0 - &gt; URL标识符(VALUE:testlink)
在App的主页中添加以下代码。
componentDidMount() {
Linking.addEventListener('url', this._handleOpenURL);
},
componentWillUnmount() {
Linking.removeEventListener('url', this._handleOpenURL);
},
_handleOpenURL(event) {
console.log(event.url);
}
&#13;
答案 0 :(得分:4)
您是否在XCode中添加了testlink://
作为网址类型?
出于本示例的目的,我的Bundle Identifier是:org.reactjs.native.example.MyApp
Info
标签URL Types
org.reactjs.native.example.MyApp.linking
testlink
testlink://
- 它应该会打开您的应用。