Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhangkn/5b870d502f15734bea713308b744dda4 to your computer and use it in GitHub Desktop.
Save zhangkn/5b870d502f15734bea713308b744dda4 to your computer and use it in GitHub Desktop.
Create a UIWebClip
UIWebClip *clip = [UIWebClip webClipWithIdentifier:nil];
//UIWebClip *clip = [UIWebClip webClipWithURL:[webpage.request.mainDocumentURL absoluteString]];
[clip retain];
[clip setPageURL:webpage.request.mainDocumentURL];
[clip setTitle:[webpage stringByEvaluatingJavaScriptFromString:@"document.title"]];
UIWebDocumentView *docView = nil;
UIScrollView *webpagescroller = [[webpage subviews] objectAtIndex:0];
for (UIView* aView in [webpagescroller subviews]){
if ([aView isKindOfClass:[NSClassFromString(@"UIWebBrowserView") class]]){
docView = (UIWebDocumentView *)aView;
}
}
[clip setIcons:[UIWebClip webClipIconsForWebDocumentView:docView]];
[clip setStatusBarStyle:[UIWebClip webClipStatusBarStyleForWebDocumentView:docView]];
[clip setFullScreen:[UIWebClip webClipFullScreenValueForWebDocumentView:docView]];
[clip setClassicMode:[UIWebClip webClipClassicModeValueForWebDocumentView:docView]];
[clip setScale:[webpagescroller zoomScale]];
CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);
NSString *uuidstr = (NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuid);
[clip setIdentifier:uuidstr];
UIApplication *app = [UIApplication sharedApplication];
[app addWebClipToHomeScreen:[clip identifier]];
[clip release];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment