问题描述
我在使用 Capacitor 在 IOS 上使用 React Ionic 打开另一个应用程序时遇到问题。 canopenUrl 始终返回 true,即使未安装应用 (bankid)。当我运行 openUrl 时什么也没有发生。
//First i import capacitor
import {Capacitor} from '@capacitor/core';
const Login: React.FC = () => {
const openBankID = async () => {
const iosURL = 'bankid://app.bankid.com/?autostarttoken=${token}&redirect=app://'
const res = await Capacitor.Plugins?.App.canopenUrl({ url: iosURL });
if (res != undefined) {
await Capacitor.Plugins?.App.openUrl({ url: iosURL })
} else {
alert("Can't open the application");
}
}
return (
<IonPage className="LoginPage">
<IonContent fullscreen className="LoginPage">
<IonCol size="12">
<IonButton
onClick={() => {
openBankID();
}} expand="block" disabled={false}>
Logga in med BankID
</IonButton>
</IonCol>
</IonContent>
</IonPage>
);
};
export default Login;
)
我还在 info.plist 中添加了我要打开的应用
<key>LSApplicationQueriesSchemes</key>
<array>
<string>bankid</string>
<string>bankid://</string>
<string>bankid://*</string>
</array>
解决方法
常量 static uint F(Time t)
{
uint r = 0;
r += t.DAY * (24 * 60 * 60);
r += t.HOUR * (60 * 60);
r += t.MIN * 60;
r += t.SEC;
return r;
}
将始终是一个对象,因此它不会是 res
。从 the docs 开始,undefined
的签名是:
canOpenUrl
如果您将条件从 canOpenUrl(options: { url: string; }) => Promise<{ value: boolean; }>
修改为 if (res != undefined)
,它应该会起作用。