SMSDemoPolicyManager.m 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. //
  2. // SMSDemoPolicyManager.m
  3. // SecVerifyDemo
  4. //
  5. // Created by hower on 2019/12/5.
  6. // Copyright © 2019 mob. All rights reserved.
  7. //
  8. #import "SMSDemoPolicyManager.h"
  9. #import "SMSDemoHelper.h"
  10. //#import <MOBFoundation/MOBFDevice.h>
  11. #import "SMSDemoPolicyWebVC.h"
  12. static UIWindow *window = nil;
  13. static UIButton *refuseView = nil;
  14. static UIButton *acceptView = nil;
  15. #define KRefuseBtnTag 19991
  16. #define KAcceptBtnTag 19992
  17. @interface SMSSDKDemoDialogVC : UIViewController<UITextViewDelegate>
  18. @property (nonatomic, assign)BOOL isPortait;
  19. @property (nonatomic, copy)SMSDemoPolicyAcceptHandler acceptBlock;
  20. @property (nonatomic, strong)NSString *url;
  21. @end
  22. @implementation SMSSDKDemoDialogVC
  23. - (void)viewDidLoad
  24. {
  25. [super viewDidLoad];
  26. self.view.backgroundColor = [UIColor clearColor];
  27. [self loadUI];
  28. }
  29. - (void)viewWillAppear:(BOOL)animated
  30. {
  31. [super viewWillAppear:animated];
  32. [self.navigationController setNavigationBarHidden:YES];
  33. }
  34. - (void)viewWillDisappear:(BOOL)animated
  35. {
  36. [super viewWillDisappear:animated];
  37. [self.navigationController setNavigationBarHidden:NO];
  38. }
  39. - (void)refuseAction:(UIButton *)btn
  40. {
  41. acceptView.selected = NO;
  42. refuseView.selected = YES;
  43. acceptView.backgroundColor = [UIColor whiteColor];
  44. refuseView.backgroundColor = [UIColor colorWithRed:8/255.0 green:151/255.0 blue:156/255.0 alpha:1];
  45. if(window)
  46. {
  47. window.hidden = YES;
  48. [window resignKeyWindow];
  49. }
  50. dispatch_time_t dipatchTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.03 * NSEC_PER_SEC));
  51. dispatch_after(dipatchTime, dispatch_get_main_queue(), ^{
  52. if (window) {
  53. window = nil;
  54. }
  55. });
  56. //存储
  57. [[NSUserDefaults standardUserDefaults] setObject:@(NO) forKey:@"smsdemo_accept_policy"];
  58. [[NSUserDefaults standardUserDefaults] synchronize];
  59. if(self.acceptBlock)
  60. {
  61. self.acceptBlock(NO);
  62. }
  63. }
  64. - (void)acceptAction:(UIButton *)btn
  65. {
  66. acceptView.selected = YES;
  67. refuseView.selected = NO;
  68. refuseView.backgroundColor = [UIColor whiteColor];
  69. acceptView.backgroundColor = [UIColor colorWithRed:8/255.0 green:151/255.0 blue:156/255.0 alpha:1];
  70. if(window)
  71. {
  72. window.hidden = YES;
  73. }
  74. dispatch_time_t dipatchTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.03 * NSEC_PER_SEC));
  75. dispatch_after(dipatchTime, dispatch_get_main_queue(), ^{
  76. if (window) {
  77. window = nil;
  78. }
  79. });
  80. //存储
  81. [[NSUserDefaults standardUserDefaults] setObject:@(YES) forKey:@"smsdemo_accept_policy"];
  82. [[NSUserDefaults standardUserDefaults] synchronize];
  83. if(self.acceptBlock)
  84. {
  85. self.acceptBlock(YES);
  86. }
  87. }
  88. +(NSString *)getTitle
  89. {
  90. if(![SMSDemoHelper isZhHans])
  91. {
  92. return @"Terms of Use";
  93. }
  94. return @"服务授权";
  95. }
  96. +(NSString *)getUpdateDate
  97. {
  98. if(![SMSDemoHelper isZhHans])
  99. {
  100. return @"update date: 2019-10-12";
  101. }
  102. return @"最近更新日期:2019年10月12日";
  103. }
  104. +(NSString *)getEffectiveDate
  105. {
  106. if(![SMSDemoHelper isZhHans])
  107. {
  108. return @"effective date: 2019-10-19";
  109. }
  110. return @"版本生效日期:2019年10月19日";
  111. }
  112. -(NSString *)getContent
  113. {
  114. NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
  115. if(self.url)
  116. {
  117. if(![SMSDemoHelper isZhHans])
  118. {
  119. return [NSString stringWithFormat:@"You are welcome to use %@. Smssdk provides developers with a free SMS verification code service. The top channel is issued in 3 seconds, which is suitable for login, password retrieval, payment authentication and other scenarios. We will use mobtech's privacy policy to help you understand what data we need to collect. Please refer to our privacy policy at %@ for details",[infoDictionary objectForKey:@"CFBundleDisplayName"],self.url];
  120. }
  121. return [NSString stringWithFormat:@" 欢迎您使用%@,为了实现找回密码、绑定账号等功能,我们使用了MobTech的SMSSDK产品,此产品的隐私策略条款,可以参考:%@",[infoDictionary objectForKey:@"CFBundleDisplayName"],self.url];
  122. }
  123. if(![SMSDemoHelper isZhHans])
  124. {
  125. return [NSString stringWithFormat:@"You are welcome to use %@, Smssdk provides developers with a free SMS verification code service. The top channel is issued in 3 seconds, which is suitable for login, password retrieval, payment authentication and other scenarios. We will use mobtech's privacy policy to help you understand what data we need to collect. Please refer to our privacy policy at http://www.mob.com/about/policy for details",[infoDictionary objectForKey:@"CFBundleDisplayName"]];
  126. }
  127. return [NSString stringWithFormat:@" 欢迎您使用%@,为了实现找回密码、绑定账号等功能,我们使用了MobTech的SMSSDK产品,此产品的隐私策略条款,可以参考:http://www.mob.com/about/policy",[infoDictionary objectForKey:@"CFBundleDisplayName"]];
  128. }
  129. -(NSString *)getContentPre
  130. {
  131. if(self.url)
  132. return self.url;
  133. return @"http://www.mob.com/about/policy";
  134. }
  135. +(NSString *)getRefuseTitle
  136. {
  137. if(![SMSDemoHelper isZhHans])
  138. {
  139. return @"Disagree";
  140. }
  141. return @"拒绝";
  142. }
  143. +(NSString *)getAcceptTitle
  144. {
  145. if(![SMSDemoHelper isZhHans])
  146. {
  147. return @"Agree";
  148. }
  149. return @"同意";
  150. }
  151. +(NSString *)getNoQueryTitle {
  152. if(![SMSDemoHelper isZhHans])
  153. {
  154. return @"Don't show again";
  155. }
  156. return @"不再询问";
  157. }
  158. - (void)loadUI {
  159. //背景
  160. UIView *containtView = [[UIView alloc] init];
  161. containtView.layer.masksToBounds = YES;
  162. containtView.layer.cornerRadius = 17;
  163. containtView.translatesAutoresizingMaskIntoConstraints = NO;
  164. containtView.backgroundColor = [UIColor whiteColor];
  165. [self.view addSubview:containtView];
  166. //标题
  167. UILabel * titleLabel = [UILabel new];
  168. titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
  169. titleLabel.text = [SMSSDKDemoDialogVC getTitle];
  170. titleLabel.textColor = UIColor.blackColor;
  171. titleLabel.backgroundColor = [UIColor clearColor];
  172. titleLabel.textAlignment = NSTextAlignmentCenter;
  173. titleLabel.font = [UIFont boldSystemFontOfSize:18];
  174. [containtView addSubview:titleLabel];
  175. //update date
  176. UILabel * updateLabel = [UILabel new];
  177. updateLabel.translatesAutoresizingMaskIntoConstraints = NO;
  178. updateLabel.textColor = [UIColor colorWithRed:171/255.0 green:171/255.0 blue:171/255.0 alpha:1];
  179. updateLabel.textAlignment = NSTextAlignmentCenter;
  180. updateLabel.backgroundColor = [UIColor clearColor];
  181. updateLabel.font = [UIFont systemFontOfSize:14];
  182. updateLabel.text = [SMSSDKDemoDialogVC getUpdateDate];
  183. [containtView addSubview:updateLabel];
  184. //effectiveDate
  185. UILabel *effectiveLabel = [UILabel new];
  186. effectiveLabel.textColor = [UIColor colorWithRed:171/255.0 green:171/255.0 blue:171/255.0 alpha:1];
  187. effectiveLabel.textAlignment = NSTextAlignmentCenter;
  188. effectiveLabel.translatesAutoresizingMaskIntoConstraints = NO;
  189. effectiveLabel.backgroundColor = [UIColor whiteColor];
  190. effectiveLabel.font = [UIFont systemFontOfSize:14];
  191. effectiveLabel.text = [SMSSDKDemoDialogVC getEffectiveDate];
  192. [containtView addSubview:effectiveLabel];
  193. //内容
  194. UITextView * contentLabel = [UITextView new];
  195. contentLabel.translatesAutoresizingMaskIntoConstraints = NO;
  196. contentLabel.backgroundColor = [UIColor clearColor];
  197. contentLabel.textAlignment = NSTextAlignmentRight;
  198. contentLabel.delegate = self;
  199. contentLabel.editable = NO;
  200. [containtView addSubview:contentLabel];
  201. UIButton *refuseBtn = [[UIButton alloc] init];
  202. refuseBtn.layer.masksToBounds = YES;
  203. refuseBtn.layer.cornerRadius = 17;
  204. refuseBtn.translatesAutoresizingMaskIntoConstraints = NO;
  205. [refuseBtn setTitle:[SMSSDKDemoDialogVC getRefuseTitle] forState:UIControlStateNormal];
  206. [refuseBtn.titleLabel setFont:[UIFont systemFontOfSize:16]];
  207. [refuseBtn addTarget:self action:@selector(refuseAction:) forControlEvents:UIControlEventTouchUpInside];
  208. [refuseBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  209. [refuseBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
  210. [containtView addSubview:refuseBtn];
  211. refuseView = refuseBtn;
  212. UIButton *acceptBtn = [[UIButton alloc] init];
  213. acceptBtn.layer.masksToBounds = YES;
  214. acceptBtn.layer.cornerRadius = 17;
  215. acceptBtn.translatesAutoresizingMaskIntoConstraints = NO;
  216. [acceptBtn setTitle:[SMSSDKDemoDialogVC getAcceptTitle] forState:UIControlStateNormal];
  217. [acceptBtn.titleLabel setFont:[UIFont systemFontOfSize:16]];
  218. [acceptBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  219. [acceptBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
  220. acceptBtn.backgroundColor = [UIColor colorWithRed:8/255.0 green:151/255.0 blue:156/255.0 alpha:1];
  221. acceptBtn.selected = YES;
  222. [acceptBtn addTarget:self action:@selector(acceptAction:) forControlEvents:UIControlEventTouchUpInside];
  223. [containtView addSubview:acceptBtn];
  224. acceptView = acceptBtn;
  225. if(window.frame.size.width > window.frame.size.height)
  226. {
  227. }
  228. else
  229. {
  230. //竖屏
  231. float widthMut = RQ_isPad?0.4f:0.86f;
  232. //计算 string 的高度
  233. float contentheight = [[self generateAttStr:self.url] boundingRectWithSize:CGSizeMake(widthMut*([UIScreen mainScreen].bounds.size.width-40), MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil].size.height+5;
  234. contentLabel.linkTextAttributes = @{NSForegroundColorAttributeName: [UIColor colorWithRed:8/255.0 green:151/255.0 blue:156/255.0 alpha:1]};
  235. //背景layout
  236. {
  237. NSLayoutConstraint * centerX = [NSLayoutConstraint constraintWithItem:containtView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0];
  238. NSLayoutConstraint * centerY = [NSLayoutConstraint constraintWithItem:containtView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1.0f constant:0];
  239. NSLayoutConstraint * width = [NSLayoutConstraint constraintWithItem:containtView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeWidth multiplier:widthMut constant:0];
  240. NSLayoutConstraint * height = [NSLayoutConstraint constraintWithItem:containtView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:200+contentheight];
  241. [self.view addConstraint:centerX];
  242. [self.view addConstraint:centerY];
  243. [self.view addConstraint:width];
  244. [containtView addConstraint:height];
  245. }
  246. {
  247. NSLayoutConstraint * top = [NSLayoutConstraint constraintWithItem:titleLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:containtView attribute:NSLayoutAttributeTop multiplier:1.0f constant:15];
  248. NSLayoutConstraint * left = [NSLayoutConstraint constraintWithItem:titleLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:containtView attribute:NSLayoutAttributeLeft multiplier:1 constant:0];
  249. NSLayoutConstraint * right = [NSLayoutConstraint constraintWithItem:titleLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:containtView attribute:NSLayoutAttributeRight multiplier:1 constant:0];
  250. NSLayoutConstraint * width = [NSLayoutConstraint constraintWithItem:titleLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:25];
  251. [containtView addConstraint:top];
  252. [containtView addConstraint:left];
  253. [containtView addConstraint:width];
  254. [containtView addConstraint:right];
  255. }
  256. //updateLabel
  257. {
  258. NSLayoutConstraint * top = [NSLayoutConstraint constraintWithItem:updateLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:containtView attribute:NSLayoutAttributeTop multiplier:1.0f constant:50];
  259. NSLayoutConstraint * left = [NSLayoutConstraint constraintWithItem:updateLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:containtView attribute:NSLayoutAttributeLeft multiplier:1 constant:0];
  260. NSLayoutConstraint * right= [NSLayoutConstraint constraintWithItem:updateLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:containtView attribute:NSLayoutAttributeRight multiplier:1 constant:0];
  261. NSLayoutConstraint * height = [NSLayoutConstraint constraintWithItem:updateLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:20];
  262. [containtView addConstraint:top];
  263. [containtView addConstraint:right];
  264. [containtView addConstraint:left];
  265. [updateLabel addConstraint:height];
  266. }
  267. //effectiveLabel
  268. {
  269. NSLayoutConstraint * top = [NSLayoutConstraint constraintWithItem:effectiveLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:containtView attribute:NSLayoutAttributeTop multiplier:1.0f constant:75];
  270. NSLayoutConstraint * left = [NSLayoutConstraint constraintWithItem:effectiveLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:containtView attribute:NSLayoutAttributeLeft multiplier:1 constant:0];
  271. NSLayoutConstraint * right= [NSLayoutConstraint constraintWithItem:effectiveLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:containtView attribute:NSLayoutAttributeRight multiplier:1 constant:0];
  272. NSLayoutConstraint * height = [NSLayoutConstraint constraintWithItem:effectiveLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:20];
  273. [containtView addConstraint:top];
  274. [containtView addConstraint:right];
  275. [containtView addConstraint:left];
  276. [effectiveLabel addConstraint:height];
  277. }
  278. //content
  279. {
  280. contentLabel.attributedText = [self generateAttStr:self.url];
  281. NSLayoutConstraint * top = [NSLayoutConstraint constraintWithItem:contentLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:containtView attribute:NSLayoutAttributeTop multiplier:1.0f constant:100];
  282. NSLayoutConstraint * left = [NSLayoutConstraint constraintWithItem:contentLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:containtView attribute:NSLayoutAttributeLeft multiplier:1 constant:20];
  283. NSLayoutConstraint * right = [NSLayoutConstraint constraintWithItem:contentLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:containtView attribute:NSLayoutAttributeRight multiplier:1 constant:-20];
  284. NSLayoutConstraint * height = [NSLayoutConstraint constraintWithItem:contentLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:contentheight+26];
  285. [containtView addConstraint:top];
  286. [containtView addConstraint:left];
  287. [containtView addConstraint:right];
  288. [contentLabel addConstraint:height];
  289. }
  290. {
  291. refuseBtn.backgroundColor = [UIColor colorWithRed:235/255.0 green:234/255.0 blue:236/255.0 alpha:1];
  292. NSLayoutConstraint * bottom = [NSLayoutConstraint constraintWithItem:refuseBtn attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:containtView attribute:NSLayoutAttributeBottom multiplier:1.0f constant:-15];
  293. NSLayoutConstraint * centerX = [NSLayoutConstraint constraintWithItem:refuseBtn attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:containtView attribute:NSLayoutAttributeCenterX multiplier:0.5 constant:0];
  294. NSLayoutConstraint * height = [NSLayoutConstraint constraintWithItem:refuseBtn attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:38];
  295. NSLayoutConstraint * width = [NSLayoutConstraint constraintWithItem:refuseBtn attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:containtView attribute:NSLayoutAttributeWidth multiplier:0.4 constant:0];
  296. [containtView addConstraint:bottom];
  297. [containtView addConstraint:centerX];
  298. [containtView addConstraint:width];
  299. [refuseBtn addConstraint:height];
  300. }
  301. {
  302. NSLayoutConstraint * bottom = [NSLayoutConstraint constraintWithItem:acceptBtn attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:containtView attribute:NSLayoutAttributeBottom multiplier:1.0f constant:-15];
  303. NSLayoutConstraint * centerX = [NSLayoutConstraint constraintWithItem:acceptBtn attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:containtView attribute:NSLayoutAttributeCenterX multiplier:1.5 constant:0];
  304. NSLayoutConstraint * height = [NSLayoutConstraint constraintWithItem:acceptBtn attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:38];
  305. NSLayoutConstraint * width = [NSLayoutConstraint constraintWithItem:acceptBtn attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:containtView attribute:NSLayoutAttributeWidth multiplier:0.4 constant:0];
  306. [containtView addConstraint:bottom];
  307. [containtView addConstraint:centerX];
  308. [containtView addConstraint:width];
  309. [acceptBtn addConstraint:height];
  310. }
  311. }
  312. }
  313. -(NSMutableAttributedString *)generateAttStr:(NSString *)url
  314. {
  315. NSString *content = [self getContent];
  316. NSString *contentPre = [self getContentPre];
  317. NSRange range = [content rangeOfString:contentPre];
  318. float fontSize = 14.0;
  319. NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:content];
  320. if(range.location !=NSNotFound)
  321. {
  322. //段落样式
  323. NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
  324. //行间距
  325. paraStyle.lineSpacing = 5.0;
  326. [attr addAttributes:@{
  327. NSParagraphStyleAttributeName:paraStyle,
  328. NSForegroundColorAttributeName:[UIColor blackColor],
  329. NSFontAttributeName:[UIFont systemFontOfSize:fontSize]
  330. } range:NSMakeRange(0, content.length)];
  331. [attr addAttributes:@{
  332. NSForegroundColorAttributeName:[UIColor colorWithRed:8/255.0 green:151/255.0 blue:156/255.0 alpha:1],
  333. NSFontAttributeName:[UIFont boldSystemFontOfSize:fontSize],
  334. NSLinkAttributeName:contentPre
  335. } range:range];
  336. }
  337. return attr;
  338. }
  339. - (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange
  340. {
  341. if([URL.absoluteString isEqualToString:[self getContentPre]])
  342. {
  343. SMSDemoPolicyWebVC *vc = [[SMSDemoPolicyWebVC alloc] init];
  344. vc.url = URL.absoluteString;
  345. [self.navigationController pushViewController:vc animated:YES];
  346. vc.title = [SMSSDKDemoDialogVC getTitle];
  347. return NO;
  348. }
  349. return YES;
  350. }
  351. - (BOOL)shouldAutorotate {
  352. return YES;
  353. }
  354. - (UIInterfaceOrientationMask)supportedInterfaceOrientations
  355. {
  356. return _isPortait?UIInterfaceOrientationMaskPortrait:UIInterfaceOrientationMaskLandscape;
  357. }
  358. - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
  359. {
  360. return _isPortait?UIInterfaceOrientationPortrait:UIInterfaceOrientationLandscapeLeft;
  361. }
  362. @end
  363. @interface SMSDemoPolicyManager ()
  364. @property (nonatomic, weak) UIViewController *curVC;
  365. @property (nonatomic, copy)SMSDemoPolicyAcceptHandler acceptBlock;
  366. @end
  367. @implementation SMSDemoPolicyManager
  368. + (instancetype)defaultManager
  369. {
  370. static SMSDemoPolicyManager *_instance = nil;
  371. static dispatch_once_t once;
  372. dispatch_once(&once, ^{
  373. _instance = [[SMSDemoPolicyManager alloc] init];
  374. });
  375. return _instance;
  376. }
  377. +(void)show:(NSString *)url compeletion:(nullable SMSDemoPolicyAcceptHandler)acceptBlock
  378. {
  379. BOOL accept = [[[NSUserDefaults standardUserDefaults] objectForKey:@"smsdemo_accept_policy"] boolValue];
  380. if(accept)
  381. {
  382. return;
  383. }
  384. [[SMSDemoPolicyManager defaultManager] show:url compeletion:acceptBlock];
  385. }
  386. -(void)show:(NSString *)url compeletion:(nullable SMSDemoPolicyAcceptHandler)acceptBlock
  387. {
  388. dispatch_async(dispatch_get_main_queue(), ^{
  389. if(window != nil)
  390. {
  391. window.hidden = YES;
  392. window = nil;
  393. }
  394. SMSSDKDemoDialogVC *vc = [[SMSSDKDemoDialogVC alloc] init];
  395. vc.acceptBlock = acceptBlock;
  396. vc.url = url;
  397. UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
  398. if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
  399. {
  400. vc.isPortait = NO;
  401. }
  402. else
  403. {
  404. vc.isPortait = YES;
  405. }
  406. self.curVC = vc;
  407. UINavigationController *navVC = [[UINavigationController alloc] initWithRootViewController:vc];
  408. navVC.navigationBarHidden = YES;
  409. //弹窗
  410. window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  411. window.backgroundColor = [UIColor colorWithWhite:0 alpha:0.6];
  412. window.rootViewController = navVC;
  413. window.windowLevel = UIWindowLevelAlert+10;
  414. window.hidden = NO;
  415. });
  416. }
  417. @end