问题:有时候,我们在做App项目时,不需要做注册登录页面
®️,但是,这个App必须要有隐私政策和用户协议
。所以,在第一次打开App时,就需要先进入到隐私政策
页面。
1、首先,自定义一个UIViewController
,可以在这个UIViewController
上自定义一些按钮或其他内容,点击按钮可以直接到加载HTML
格式的隐私政策WKWebView
页面:
GW_PrivacyPolicy_VC.h:
@interface GW_PrivacyPolicy_VC : GWBaseViewController
/**
* 同意隐私政策之后,继续,拒绝,提示:APP不可用
*/
@property (nonatomic, copy) void (^agreePrivacyPolicy_Block) (BOOL is_Agree);
@end
GW_PrivacyPolicy_VC.m:
#import "GW_PrivacyPolicy_VC.h"
#import "GW_PrivacyPolicy_PopView.h" // 隐私政策 弹窗
@interface GW_PrivacyPolicy_VC ()
@end
@implementation GW_PrivacyPolicy_VC
- (void)viewDidLoad {
[super viewDidLoad];
self.statusBg.hidden = YES;
self.leftButton.hidden = YES;
self.rightButton.hidden = YES;
self.navigationBar.hidden = YES;
__weak typeof(self)weakSelf = self;
GW_PrivacyPolicy_PopView *popView = [[GW_PrivacyPolicy_PopView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
[self.view addSubview:popView];
popView.agreePrivacyPolicy_ContinueBlock = ^(BOOL is_Agree) { // 同意,继续代码
if (weakSelf.agreePrivacyPolicy_Block) {
weakSelf.agreePrivacyPolicy_Block(is_Agree);
}
};
return;
}
@end
2、使用:将这个自定义的UIViewController
在AppDelegate.m
中跳转,
- 原理:在打开App时,先判断其是否已经同意“隐私政策”,如果同意就跳到首页,否则,就是没同意,跳到“隐私政策”页面,不同意,无法使用改App。
AppDelegate.h:
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
AppDelegate.m:
#import "AppDelegate.h"
#import "KMainTabBarController.h"
#import "GW_PrivacyPolicy_VC.h"
@interface AppDelegate ()
@property (nonatomic, strong) KMainTabBarController *mainTabBarController;
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
self.window.backgroundColor = [UIColor whiteColor];
self.mainTabBarController = [[KMainTabBarController alloc] init];
self.window.rootViewController = self.mainTabBarController;
[self.window makeKeyAndVisible];
// 判断是否有保存到本地的标志:NSUserDefaults(同意“隐私政策” 保存1,否则就是nil或0)
NSString *is_AgreeStr = [[NSUserDefaults standardUserDefaults] objectForKey:@"is_Agree_App_PrivacyPolicy"];
if (![is_AgreeStr isEqualToString:@"1"]) {
GW_PrivacyPolicy_VC *privacyPolicyVC = [[GW_PrivacyPolicy_VC alloc] init];
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:privacyPolicyVC];
privacyPolicyVC.agreePrivacyPolicy_Block = ^(BOOL is_Agree) {
// 同意隐私政策之后,再跳转首页
self.mainTabBarController.selectedIndex = 0;
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:self.mainTabBarController];
self.mainTabBarController.navigationController.navigationBarHidden = YES; // (如果首页不带 系统导航栏 的话)不添加这一行的话,第一次运行会有导航栏,是其上面那一行造成的
// 定位权限(获取定位)(这种操作,在进入页面之后在判断)
//[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
};
} else {
//[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
}
return YES;
}
@end
网友评论