从UIwebview打开并安装iOS应用程序

时间:2014-05-19 06:59:01

标签: ios objective-c uiwebview app-store

我有来自AppStore的链接制作者的应用程序链接。我的应用中有UIWebView,我正在尝试加载UIWebView中的链接,但每次加载该链接时,都会打开内置的AppStore,而不是在UIWebView中显示内容。我想打开UIWebView中的链接,而不是打开内置的iOS AppStore。

这是我试过的

- (void)viewDidLoad
{
    str = @"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa";
    str = [NSString stringWithFormat:@"%@/wa/viewContentsUserReviews?", str];
    str = [NSString stringWithFormat:@"%@type=Purple+Software&id=", str];

    // Here is the app id from itunesconnect
    str = [NSString stringWithFormat:@"%@289382458", str];

   [webOpenApp loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
}

-(BOOL) webView:(UIWebView *)inWeb
shouldStartLoadWithRequest:(NSURLRequest *)inRequest
 navigationType:(UIWebViewNavigationType)inType
{
    if (inType == UIWebViewNavigationTypeOther) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
        return NO;
    }

    return YES;
}

1 个答案:

答案 0 :(得分:1)

itms-apps://是一种特殊协议,当iOS系统读取此内容时,它将启动App Store以显示该应用。显然这不是你想要的。

您应该自己构建UI以显示应用程序的信息。当用户单击“购买”按钮时,您必须将用户重定向到App Store。因为App Store是用户可以购买和下载应用程序的唯一地方。