当我使用下面的代码检查我的设备上是否安装了应用程序时,它会完成这项工作,我检查,如果没有安装它将会安装,到目前为止一切都很好。 然而问题是当安装应用程序时我想直接打开应用程序,现在发生的是链接打开应用程序商店(正如预期)但我必须手动按下打开按钮,我想知道这是否可以在没有不得不按下打开按钮。
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:
@"https://itunes.apple.com/xxx"]])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/xxx"]]; }
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"App not installed on Device" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Open link", nil];
[alert show];
}
答案 0 :(得分:1)
如果您要打开的应用已定义custom scheme,则可以通过使用以该方案开头的网址openURL:
直接打开它。在您的代码中,它看起来像:
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:
@"theAppsCustomScheme://xxx"]])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"theAppsCustomScheme://xxx"]];
}
else
{
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:
@"https://itunes.apple.com/xxx"]])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/xxx"]];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"The AppStore cannot be launched, please install the app manually" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Open link", nil];
[alert show];
}
}
您可以检查应用是否在其.plist
文件中有自定义方案。它必须有一个" URL类型" /" URL方案" [0]项。