苹果今天拒绝了我的应用程序建议,除其他事项外,我不应强迫我的用户访问我的网页访问我的网页.他们建议使用iOS9中新增的SafariWebController.我去寻找指导,只找到了Swift教程.
我一直在使用以下命令启动Safari,与按钮相关联:
NSURL *url = [NSURL URLWithString:WEBSITE_REGISTRATION_URL];
[[UIApplication sharedApplication] openURL:url];
Run Code Online (Sandbox Code Playgroud)
所以,我会分享我的简单配置,让我们这些人试图跟上那些尚未使用Swift的人.
Ste*_*STL 39
有5个步骤:
单击项目目标,然后选择"构建阶段".在"Build Phases"下,单击"Link Binary with Libraries"箭头,然后单击加号.在将打开的窗口中搜索SafariServices.在列表中突出显示它,然后单击"添加".

将库导入到按钮所在的.m文件中:
#import <SafariServices/SafariServices.h>
Run Code Online (Sandbox Code Playgroud)在.m文件中定义类扩展以符合Safari VC协议:
@interface SKWelcomeViewController () <SFSafariViewControllerDelegate>
Run Code Online (Sandbox Code Playgroud)实现以下委托方法,当需要解除对Safari View Controller的解雇时将调用该方法:
- (void)safariViewControllerDidFinish:(SFSafariViewController *)controller {
[self dismissViewControllerAnimated:true completion:nil];
}
Run Code Online (Sandbox Code Playgroud)最后,IBAction中的代码:
SFSafariViewController *svc = [[SFSafariViewController alloc] initWithURL:url];
svc.delegate = self;
[self presentViewController:svc animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)请享用!
| 归档时间: |
|
| 查看次数: |
11197 次 |
| 最近记录: |