【发布时间】:2016-06-07 08:19:21
【问题描述】:
如何在 iOS 上的 React Native 应用程序中将用户正确链接到 App Store 应用程序的评论页面?
【问题讨论】:
标签: ios app-store react-native
如何在 iOS 上的 React Native 应用程序中将用户正确链接到 App Store 应用程序的评论页面?
【问题讨论】:
标签: ios app-store react-native
【讨论】:
LSApplicationQueriesSchemes,如下所述:facebook.github.io/react-native/docs/linking.html#canopenurl
itms:// 替换为 itms-apps://
这是类似的,它显示一个更新应用程序的警告框,并根据他们的设备操作系统打开 Play 商店或应用商店。
function updateAppNotice(){
const APP_STORE_LINK = 'itms://itunes.apple.com/us/app/apple-store/myiosappid?mt=8';
const PLAY_STORE_LINK = 'market://details?id=myandroidappid';
Alert.alert(
'Update Available',
'This version of the app is outdated. Please update app from the '+(Platform.OS =='ios' ? 'app store' : 'play store')+'.',
[
{text: 'Update Now', onPress: () => {
if(Platform.OS =='ios'){
Linking.openURL(APP_STORE_LINK).catch(err => console.error('An error occurred', err));
}
else{
Linking.openURL(PLAY_STORE_LINK).catch(err => console.error('An error occurred', err));
}
}},
]
);
}
【讨论】:
mt=8 是做什么的?我想知道这是否是特定地区的和必要的?
对于 iOS,您必须将 LSApplicationQueriesSchemes 作为数组参数添加到 Info.plist 并向其中添加项目。
例如到 AppStore 链接,我使用 itms-apps 作为此数组中的参数之一。
例如:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>itms-apps</string>
</array>
你的链接应该是这样的
itms-apps://itunes.apple.com/us/app/id${APP_STORE_LINK_ID}?mt=8.
嗯。现在你可以用方法来做链接组件了
handleClick () {
Linking.canOpenURL(link).then(supported => {
supported && Linking.openURL(link);
}, (err) => console.log(err));
}
【讨论】:
LSApplicationQueriesSchemes 仅在为 iOS 9+ 构建时才需要:facebook.github.io/react-native/docs/linking.html#canopenurl
LSApplicationQueriesSchemes:LSApplicationQueriesSchemes 键的值是一个包含您要支持的 URL 的数组。
<key>LSApplicationQueriesSchemes</key> <array> <string>itms-apps</string> </array>
我正在使用这个library。似乎还不错。您只需要指定包名称和应用商店 ID 并调用该函数。而且它也是跨平台的。
render() {
return (
<View>
<Button title="Rate App" onPress={()=>{
let options = {
AppleAppID:"2193813192",
GooglePackageName:"com.mywebsite.myapp",
AmazonPackageName:"com.mywebsite.myapp",
OtherAndroidURL:"http://www.randomappstore.com/app/47172391",
preferredAndroidMarket: AndroidMarket.Google,
preferInApp:false,
openAppStoreIfInAppFails:true,
fallbackPlatformURL:"http://www.mywebsite.com/myapp.html",
}
Rate.rate(options, (success)=>{
if (success) {
// this technically only tells us if the user successfully went to the Review Page. Whether they actually did anything, we do not know.
this.setState({rated:true})
}
})
} />
</View>
)
}
【讨论】:
使用第三方库,在ios中是打开itunes,我告诉你打开appstore的具体方法。 首先你应该是活的,它会在物理设备上工作(不保证模拟器)
const url = Platform.OS === 'android' ?
'https://play.google.com/store/apps/details?id=YOUR_APP_ID' : 'https://apps.apple.com/us/app/doorhub-driver/id_YOUR_APP_ID'
Linking.openURL(url)
您可以通过在 appstore 上搜索您的应用并复制该网址来找到您的 ios 链接。
【讨论】:
其他一些答案相当陈旧,不支持使用 iOS 10.3 (SKStoreReviewController) 和 Android 5 (ReviewManager) 中添加的应用内评论 API。如果您在 2021 年为您的 React Native 应用添加评论,那么您最好使用这些评论(如果可用)。
Expo 提供了一个库 https://docs.expo.io/versions/latest/sdk/storereview/ ,如果用户的设备支持这些更新的 API,它将使用它们,如果不支持,则回退到打开商店页面。
还有https://github.com/KjellConnelly/react-native-rate 具有类似的功能,但配置选项更多。例如。您可以决定是否在某些时候或所有时间使用应用内 API(这可能是一个好主意,因为应用内 API 对用户的摩擦要小得多,但您只能询问几次年)。
【讨论】: