ios - 深层链接不包含有效的必需参数
问题描述
我正在尝试将 firebase 动态链接集成到 React Native 应用程序中,当我导航到前缀 url 时,我看到了正确的 json 对象,表明初始域设置成功。我已根据文档将关联的域添加到我的项目中。我遇到的问题是,当我打开使用 dynamiclinks sdk 创建的链接之一时,我在 xcode 中收到此错误。
[Firebase/Analytics][I-ACS023001] Deep Link does not contain valid required params. URL params: {
socialDescription = "Check out business name on our app";
socialImageUrl = "http://[apiurl]//rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBCZz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--046e60135790b0344b8ac127c4e8bcf8ad7cd216/cover.png";
socialTitle = "\"Business name\" on our app";
}
这就是我创建链接的方式..
const link = await dynamicLinks().buildShortLink({
link:'https://myapp.page.link/id=${props.business.id}',
domainUriPrefix: 'https://myApp.page.link',
ios: {
bundleId: 'com.myApp.app',
appStoreId: '123456589',
minimumVersion: '12',
},
social: {
imageUrl: `${API_URL}${cover_image}`,
title: `"Check out ${props.business.name}" on our app`,
descriptionText: `Check out ${props.business.name} on our app`,
},
});
Share.share({
url: link,
title: 'Check this out!',
});
这是我添加到 appdelegate 以处理传入链接的内容
- (BOOL)application:(UIApplication *)application
continueUserActivity:(nonnull NSUserActivity *)userActivity
restorationHandler:
#if defined(__IPHONE_12_0) && (__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_12_0)
(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> *_Nullable))restorationHandler {
#else
(nonnull void (^)(NSArray *_Nullable))restorationHandler {
#endif // __IPHONE_12_0
BOOL handled = [[FIRDynamicLinks dynamicLinks] handleUniversalLink:userActivity.webpageURL completion:^(FIRDynamicLink * _Nullable dynamicLink, NSError * _Nullable error) {
// ... }];
return handled;
}
- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary<NSString *, id> *)options {
return [self application:app
openURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
FIRDynamicLink *dynamicLink = [[FIRDynamicLinks dynamicLinks] dynamicLinkFromCustomSchemeURL:url];
if (dynamicLink) {
if (dynamicLink.url) {
// Handle the deep link. For example, show the deep-linked content,
// apply a promotional offer to the user's account or show customized onboarding view.
// ...
} else {
// Dynamic link has empty deep link. This situation will happens if
// Firebase Dynamic Links iOS SDK tried to retrieve pending dynamic link,
// but pending link is not available for this device/App combination.
// At this point you may display default onboarding view.
}
return YES;
}
return NO;
}
这是相应的反应本机代码
const handleDynamicLink = link => {
// Handle dynamic link inside your own application
console.log(' ', link);
};
useEffect(() => {
const unsubscribe = dynamicLinks().onLink(handleDynamicLink);
// When the component unmounts, remove the listener
return unsubscribe;
}, []);
当我在没有社交元数据的情况下建立链接时,它可以工作,但是链接没有图像。熟悉firebase动态链接的人可以告诉我这里有什么问题吗?链接缺少什么参数?
解决方案
对于那些最终遇到同样问题的人,我发现了这里发生的事情:
https://github.com/invertase/react-native-firebase/issues/3182
最后一条评论说:
当使用 url(而不是消息)字段中传递的链接直接共享到 iMessage 时,Apple 会解析链接,但 url 路径会被动态链接中的社交字段中的数据替换,这会使链接格式错误。
我的解决方案是使用“react-native-share”库而不是像这样的本机共享扩展
const url = `${link}`;
const message = `"${props.business.name}" on our app`;
const options = Platform.select({
ios: {
activityItemSources: [
{
placeholderItem: {
type: 'text',
content: `${message} ${url}`,
},
item: {
default: {
type: 'text',
content: `${message} ${url}`,
},
},
linkMetadata: {
title: `"${props.business.name}" on our app`,
},
},
],
},
default: {
message: `${message} ${url}`,
},
});
Share.open(options)
.then(res => {
console.log(res);
})
.catch(err => {
console.log(err);
});
推荐阅读
- c# - 验证包含开始和结束标签的文本
- html - 如何将边框的某个部分保持在子 div 的内容之上?
- java - 在获得价值 vikas 的标题后,如何根据他们的评级对 firebase 数据进行排序?
- javascript - Ubikloadpack jmeter 插件未附加显示错误命令如下:
- node.js - 将 HighChart 3D 饼图导出为 png 不起作用
- python - 哪个更快 - 条件字符串格式或常规 if/else?
- swift - 如何添加封面图片
- google-cloud-functions - 如何强制终止云功能?
- angular - Angular - 为生产构建 Angular 项目时出错
- javascript - 如何使用 Lodash 将对象替换或附加到另一个对象