开发者

iPhone WebApp Question

I have this code-

/** Save the web view as a screenshot. Currently only supports saving to the photo library. / - (void)saveScreenshot:(NSArray)arguments withDict:(NSDictionary*)options { CGRect screenRect = [[UIScreen mainScreen] bounds]; CGRect imageRect = CGR开发者_运维知识库ectMake(0, 0, CGRectGetWidth(screenRect), CGRectGetHeight(screenRect));

UIGraphicsBeginImageContext(imageRect.size);
[webView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, self, nil, nil);

UIAlertView *alert= [[UIAlertView alloc] initWithTitle:nil

message:@"Image Saved" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release];

}

This is for saving whatever you drew in my app. How would I add the button for this in the HTML code. How do i call from it?


So you are trying to send an event from html to a UIWebView?

The easiest way is to use a private scheme. In the html:

<a href="myscheme:save_picture">Take Picture</a>

In the UIWebView delegate:

-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
    NSString    *string = [[[inRequest URL] absoluteString] lowercaseString];
    if ( [string isEqualToString:@"myscheme:save_picture"] ) {
        [self savePicture];
        return NO;
    }
    return YES;
}

You can look at PhoneGap for a more robust usage of this mechanism.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜