Expo-通过链接导航到IOS设置时,会引发错误



我正在尝试使用expo链接将用户发送到我的应用程序IOS设置:

组件:

<Card disabled={true}>
<Text>{isSettingModalOpen}</Text>
<Button onPress={() => setIsSettingModalOpen(null)}>
DISMISS
</Button>
<Button
onPress={() => {
openAppSettings();
}}
>
Go To Settings
</Button>
</Card>

打开设置按钮的逻辑:

export const openAppSettings = async () => {
try {
if (Platform.OS === "ios") {
await Linking.openURL("app-settings:");
} else {
const pkg = Constants.manifest.releaseChannel
? Constants.manifest.android.package build
: "host.exp.exponent"; 
await IntentLauncher.startActivityAsync(
IntentLauncher.ActivityAction.APPLICATION_DETAILS_SETTINGS,
{ data: "package:" + pkg }
);
}
} catch (e) {
console.log("Error -openAppSettings-", e);
}
};

在android设备上,此代码工作没有任何问题,但在IOS设备上,当我们按下";转到设置按钮";我们得到错误:

Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?

我们的项目中没有使用任何参考,因此我们将不胜感激。

import * as IntentLauncher from 'expo-intent-launcher'
const openAppPref = () => {
if (Platform.OS === 'ios') {
Linking.openURL("App-prefs:root=General");
} else {
IntentLauncher.startActivityAsync(
IntentLauncher.ActivityAction.SECURITY_SETTINGS
)
}
}

你可以这样简单地打开在ios中,你可以很容易地使用链接,但在android中,你应该使用expo 的Intent启动器

最新更新