Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you download a passbook coupon from a UIWebView inside an IOS app?

Is it possible to download and add a passbook from within a webview without modifying the app to support the new MIME type or unknown MIME types like Sparrow did?

I have a news ios app with a webview. In the webview I display the news items and a banner. When you click the banner I want to open a url to a .pkpass file and add it to my passbook. Instead I get a FrameLoadInterrupted error and nothing visible happens. If I open the url from safari this works fine, chrome, since earlier this week (version 23) also opens the url like intended.

Is this some weird strategy from Apple maybe? not allowing this MIME type to properly open from a webview?

like image 848
Benjamin Udink ten Cate Avatar asked Nov 30 '12 14:11

Benjamin Udink ten Cate


People also ask

What is UIWebView on apple iphone?

A view that embeds web content in your app.

What does UI web view mean?

Android is powered by Chrome. Mobile Safari UIWebView. The UIWebView is different from the ordinary Safari browser, as it is not a stand-alone browser, but merely browser functionality that is embedded in a third party app that allows the app to display content from the web.


1 Answers

My best bet is that the UIWebView is just not capable of handling the Passbook passes. You could however try and catch the downloading in the UIWebViewDelegate method -(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType.

What I mean to say is that you have to handle this part your self, since the http://passkit.com/samples/ I used does not return an url which ends pkpass thus it is totally depended on how you request the passbook files.

If you do in include the .pkpass extension you can check for the extension in the request.

If you know what kind of URL the passbook file is at you write your own download code here and pass it to passbook via the passbook api.


There does not seem to be any great on fix for this, you could load the failed ULR in safari:

- (void) webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
    NSLog(@"Webview: %@", error);

    if ([error.domain isEqualToString:@"WebKitErrorDomain"] && error.code == 102) {
        NSString *failedURL = [error.userInfo objectForKey:NSURLErrorFailingURLStringErrorKey];

        if (failedURL == nil) {
            return;
        }
        NSURL *url = [NSURL URLWithString:failedURL];

        [[UIApplication sharedApplication] openURL:url];
    }
}

But this is just really bad coding.

like image 70
rckoenes Avatar answered Oct 02 '22 22:10

rckoenes