user331914
user331914

Reputation:

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 = CGRectMake(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?

Upvotes: 0

Views: 124

Answers (1)

drawnonward
drawnonward

Reputation: 53659

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.

Upvotes: 1

Related Questions