iOS 9 之后推出了SFSafariViewController
可以实现与Safari对接。
使用场景:
当APP中需要使用Safari打开的URL。可以使用SFSafariViewController
在当前APP打开。如果跳转至Safari也可以接着继续访问。
官方描述:
An object that provides a visible standard interface for browsing the web.
代码实现:
// 导入 SafariServices.framework
#import <SafariServices/SafariServices.h>
- (void)buttonAction {
NSURL *URL = [NSURL URLWithString:@"https://apple.com"];
SFSafariViewController *safariVC = [[SFSafariViewController alloc] initWithURL:URL];
safariVC.delegate = self;
[self presentViewController:safariVC animated:YES completion:^{
}];
}
// 点击分享按钮
- (NSArray<UIActivity *> *)safariViewController:(SFSafariViewController *)controller activityItemsForURL:(NSURL *)URL title:(nullable NSString *)title {
return @[];
}
// 屏蔽某些分享按钮
- (NSArray<UIActivityType> *)safariViewController:(SFSafariViewController *)controller excludedActivityTypesForURL:(NSURL *)URL title:(nullable NSString *)title API_AVAILABLE(ios(11.0)) {
return @[];
}
// 销毁controller
- (void)safariViewControllerDidFinish:(SFSafariViewController *)controller {
}
// 页面加载完成。只有初始URL加载完成时会调用。
- (void)safariViewController:(SFSafariViewController *)controller didCompleteInitialLoad:(BOOL)didLoadSuccessfully {
}
// 开始加载
- (void)safariViewController:(SFSafariViewController *)controller initialLoadDidRedirectToURL:(NSURL *)URL API_AVAILABLE(ios(11.0)) {
}
截图
Simulator Screen.png
网友评论