JYNewMineViewController.m 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584
  1. //
  2. // JYNewSearchViewController.m
  3. // JianYuIOS
  4. //
  5. // Created by apple on 2020/6/5.
  6. // Copyright © 2020 lixianglan. All rights reserved.
  7. //
  8. #import "JYNewMineViewController.h"
  9. #import <WebKit/WebKit.h>
  10. #import "JYTabBarController.h"
  11. #import <CoreLocation/CoreLocation.h>
  12. /*
  13. afterPageInit 报异常
  14. afterClickBack 侧滑返回 首页-
  15. 分享回调报异常
  16. 不能支付
  17. */
  18. @interface JYNewMineViewController ()<WKNavigationDelegate,WKUIDelegate,WKScriptMessageHandler,CLLocationManagerDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate,SKProductsRequestDelegate,WBFaceVerifyCustomerServiceDelegate,ZKClipboardViewDelegate>
  19. {
  20. CGPoint startTouch;
  21. BOOL _isMoving;
  22. BOOL isExistNoNewWork;
  23. }
  24. @property (nonatomic, strong) UIProgressView *progressView;
  25. @property (nonatomic, strong) WKWebView *webView;
  26. @property(nonatomic, assign)BOOL updateNotify;
  27. @property(nonatomic, strong)NoNetView *noNetView;
  28. @property(nonatomic, strong)NoNetView *failNetView;
  29. @property(nonatomic, strong)UIPanGestureRecognizer *recognizer;
  30. @property(nonatomic, strong)ZKClipboardView *clipboardView;
  31. @property(nonatomic, strong)ZKFaceVerifyMsgView *verifyMsgView;
  32. @end
  33. NSString *const new_kInitVector_4 = @"1389461544135476";
  34. size_t const new_kKeySize_4 = kCCKeySizeAES128;
  35. NSString *const new_AesKey_4 = @"mGlAgnIBB8bx2nch";
  36. @implementation JYNewMineViewController
  37. -(void)viewWillAppear:(BOOL)animated
  38. {
  39. [super viewWillAppear:animated];
  40. [self.navigationController setNavigationBarHidden:YES animated:animated];
  41. if([GlobalData shareInstance].mineIsRed) {
  42. [GlobalData shareInstance].mineIsRed = NO;
  43. [self webViewFirstRequest];
  44. }
  45. }
  46. //弹框
  47. -(ZKFaceVerifyMsgView *)verifyMsgView
  48. {
  49. if(!_verifyMsgView) {
  50. _verifyMsgView = [[ZKFaceVerifyMsgView alloc]initWithFrame:CGRectMake(0, 0, WIDTH*0.8, 150)];
  51. _verifyMsgView.titleName = @"温馨提示";
  52. }
  53. return _verifyMsgView;
  54. }
  55. //进度条
  56. - (UIProgressView *)progressView
  57. {
  58. if (_progressView == nil) {
  59. _progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(0,STATUS_BAR_HEIGHT - 2,WIDTH,2)];
  60. _progressView.tintColor = [UIColor blueColor];
  61. _progressView.trackTintColor = [UIColor whiteColor];
  62. }
  63. return _progressView;
  64. }
  65. //弹框
  66. -(ZKClipboardView *)clipboardView{
  67. if(!_clipboardView) {
  68. _clipboardView = [[ZKClipboardView alloc]initWithFrame:CGRectMake(0, 0, WIDTH*0.8, 180+90)];
  69. _clipboardView.delegate = self;
  70. }
  71. return _clipboardView;
  72. }
  73. //懒加载
  74. - (WKWebView *)webView
  75. {
  76. if(_webView == nil) {
  77. WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
  78. config.preferences = [[WKPreferences alloc] init];
  79. config.preferences.minimumFontSize = 0;
  80. config.allowsInlineMediaPlayback = YES;
  81. config.preferences.javaScriptEnabled = YES;
  82. config.preferences.javaScriptCanOpenWindowsAutomatically = YES;
  83. //添加消息处理,注意:self指代的是需要遵守WKScriptMessageHandler协议,结束时需要移除
  84. config.userContentController = [[WKUserContentController alloc] init];
  85. //声明协议
  86. NSArray *jsArr = @[@"loginByWeixin",
  87. @"share",
  88. @"saveUserToken",
  89. @"removeUserToken",
  90. @"openSystemNotification",
  91. @"openExternalLink",
  92. @"alert",
  93. @"hiddenBottom",
  94. @"checkLab",
  95. @"loginSuccess",
  96. @"backUrl",
  97. @"clearPushMessage",
  98. @"hideRedSpotOnMenu",
  99. @"showRedSpotOnMenu",
  100. @"wxPay",
  101. @"aliPay",
  102. @"skipCameraWithParam",
  103. @"skipAlbumWithParam",
  104. @"openActivityPage",
  105. @"callPhone",
  106. @"openOtherAppLinks",
  107. @"inPurchasingVip",
  108. @"wirteRight",
  109. @"clearRight",
  110. @"savePic",
  111. @"ocrVerifyService",
  112. @"faceVerifyService",
  113. ];
  114. for (NSString*jsName in jsArr) {
  115. [config.userContentController addScriptMessageHandler:self name:jsName];
  116. }
  117. //高端的自定义配置创建WKWebView
  118. if (iPhoneX) {
  119. _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-TAB_BAR_HEIGHT) configuration:config];
  120. if (@available(iOS 11.0, *)) {
  121. _webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  122. }
  123. }else {
  124. _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, -STATUS_BAR_HEIGHT, WIDTH, HEIGHT-TAB_BAR_HEIGHT+STATUS_BAR_HEIGHT) configuration:config];
  125. }
  126. _webView.scrollView.bounces = NO;
  127. _webView.UIDelegate = self;
  128. _webView.navigationDelegate = self;
  129. // _webView.allowsBackForwardNavigationGestures = true;
  130. _webView.userInteractionEnabled = YES;
  131. [_webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
  132. }
  133. return _webView;
  134. }
  135. -(void)webViewFirstRequest
  136. {
  137. NSString *url = [NSString stringWithFormat:@"%@%@", kHost, @"jyapp/free/me"];
  138. url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  139. NSLog(@"444 :第一次加载:%@",url);
  140. kMainQueue(^{
  141. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
  142. })
  143. }
  144. #pragma mark - event response
  145. // 计算wkWebView进度条
  146. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
  147. if (object == self.webView && [keyPath isEqualToString:@"estimatedProgress"]) {
  148. CGFloat newprogress = [[change objectForKey:NSKeyValueChangeNewKey] doubleValue];
  149. self.progressView.alpha = 1.0f;
  150. [self.progressView setProgress:newprogress animated:YES];
  151. if (newprogress >= 1.0f) {
  152. self.recognizer.enabled = YES;
  153. [UIView animateWithDuration:0.3f
  154. delay:0.3f
  155. options:UIViewAnimationOptionCurveEaseOut
  156. animations:^{
  157. self.progressView.alpha = 0.0f;
  158. }
  159. completion:^(BOOL finished) {
  160. [self.progressView setProgress:0 animated:NO];
  161. }];
  162. }
  163. } else {
  164. [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
  165. }
  166. }
  167. -(void)initNotification {
  168. //加载通知
  169. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(openPushLinkUrlMethods:) name:OpenPushLinkUrlMethods object:nil];
  170. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(openPushUrlMethodsFour:) name:OpenPushUrlMethodsFour object:nil];
  171. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jyReceiveNewsRedPoint:) name:JYReceiveNewsRedPoint object:nil];
  172. //支付状态通知
  173. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(alipayWXpayStatus:) name:AlipayWXpayStatus object:nil];
  174. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateNotifyState:) name:kUpdateNotifyState object:nil];
  175. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadWebView:) name:kReloadWebVIew object:nil];
  176. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(popWebView:) name:PopWebView object:nil];
  177. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginOut:) name:kLoginOut object:nil];
  178. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netReachChanged:) name:AFNetworkingReachabilityDidChangeNotification object:nil];
  179. //接收全新通知
  180. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshNonCurVC:) name:RefreshNonCurVC object:nil];
  181. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshAllVC:) name:RefreshAllVC object:nil];
  182. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshExpAndMine:) name:RefreshExpAndMine object:nil];
  183. //监听购买结果
  184. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiptData:) name:@"receiptData" object:nil];
  185. //粘贴板-
  186. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateClipboard:) name:UpdateClipboard object:nil];
  187. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(openTheClipboard:) name:OpenTheClipboard object:nil];
  188. }
  189. #pragma mark – Gesture Recognizer –
  190. -(void)paningGestureReceive:(UIPanGestureRecognizer *)recoginzer
  191. {
  192. NSString *current_url = [self stringByEvaluatingJavaScriptFromString:@"document.location.href"];
  193. CGRect rect = self.view.bounds;
  194. CGFloat width = CGRectGetWidth(rect);
  195. if (![self.webView canGoBack]||[current_url containsString:@"jyapp/free/login"]) {
  196. NSLog(@"不可返回");
  197. return;
  198. }
  199. if([current_url isEqualToString:[NSString stringWithFormat:@"%@jyapp/free/me",kHost]]||[current_url isEqualToString:[NSString stringWithFormat:@"%@jyapp/jylab/index",kHost]]||[current_url isEqualToString:[NSString stringWithFormat:@"%@jyapp/swordfish/historypush",kHost]]||[current_url isEqualToString:[NSString stringWithFormat:@"%@jyapp/jylab/mainSearch",kHost]]){
  200. return;
  201. }
  202. CGPoint touchPoint = [recoginzer locationInView:[UIApplication sharedApplication].keyWindow];
  203. if (recoginzer.state==UIGestureRecognizerStateBegan) {
  204. _isMoving = YES;
  205. startTouch = touchPoint;
  206. } else if (recoginzer.state==UIGestureRecognizerStateEnded||(recoginzer.state==UIGestureRecognizerStatePossible)){
  207. if (touchPoint.x - startTouch.x > width*0.125) {
  208. [UIView animateWithDuration:0.3 animations:^{
  209. if (recoginzer.state==UIGestureRecognizerStateEnded) {
  210. [self moveViewWithX:width];
  211. [self.webView goBack];
  212. }
  213. } completion:^(BOOL finished) {
  214. _isMoving = NO;
  215. [self moveViewWithX:0];
  216. }];
  217. } else {
  218. [UIView animateWithDuration:0.3 animations:^{
  219. [self moveViewWithX:0];
  220. } completion:^(BOOL finished) {
  221. _isMoving = NO;
  222. }];
  223. }
  224. return;
  225. } else if (recoginzer.state==UIGestureRecognizerStateCancelled){
  226. [UIView animateWithDuration:0.3 animations:^{
  227. [self moveViewWithX:0];
  228. } completion:^(BOOL finished) {
  229. _isMoving = NO;
  230. }];
  231. return;
  232. }else {
  233. }
  234. if (_isMoving) {
  235. [self moveViewWithX:touchPoint.x - startTouch.x];
  236. }
  237. }
  238. -(void)moveViewWithX:(float)x
  239. {
  240. CGRect rect = self.view.bounds;
  241. CGFloat width = CGRectGetWidth(rect);
  242. x = x>width?width:x;
  243. x = x<0?0:x;
  244. CGRect frame = self.webView.frame;
  245. frame.origin.x = x;
  246. self.webView.frame = frame;
  247. }
  248. - (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message{
  249. // message.body -- Allowed types are NSNumber, NSString, NSDate, NSArray,NSDictionary, and NSNull.
  250. // NSLog(@"原生收到了js发送过来的消息message.name = %@ message.body = %@",message.name,message.body);
  251. if ([message.name isEqualToString:@"loginByWeixin"]) {
  252. [self jsLoginByWeixin:message.body];
  253. }else if ([message.name isEqualToString:@"share"]) {
  254. [self jsShare:message.body];
  255. }else if ([message.name isEqualToString:@"saveUserToken"]) {
  256. [self jsSaveUserToken:message.body];
  257. }else if ([message.name isEqualToString:@"removeUserToken"]) {
  258. [self jsRemoveUserToken:message.body];
  259. }else if ([message.name isEqualToString:@"openSystemNotification"]) {
  260. [self jsOpenSystemNotification:message.body];
  261. }else if ([message.name isEqualToString:@"openExternalLink"]) {
  262. [self JsOpenExternalLink:message.body];
  263. }else if ([message.name isEqualToString:@"alert"]) {
  264. [self jsAlert:message.body];
  265. }else if ([message.name isEqualToString:@"hiddenBottom"]) {
  266. [self jsHiddenBottom:message.body];
  267. }else if ([message.name isEqualToString:@"checkLab"]) {
  268. [self jsCheckLab:message.body];
  269. }else if ([message.name isEqualToString:@"loginSuccess"]) {
  270. [self jsLoginSuccess:message.body];
  271. }else if ([message.name isEqualToString:@"backUrl"]) {
  272. [self jsBackUrl:message.body];
  273. }else if ([message.name isEqualToString:@"clearPushMessage"]) {
  274. [self jsClearPushMessage:message.body];
  275. }else if ([message.name isEqualToString:@"hideRedSpotOnMenu"]) {
  276. [self jsHideRedSpotOnMenu:message.body];
  277. }else if ([message.name isEqualToString:@"showRedSpotOnMenu"]) {
  278. [self jsShowRedSpotOnMenu:message.body];
  279. }else if ([message.name isEqualToString:@"wxPay"]) {
  280. [self jsWxPay:message.body];
  281. }else if ([message.name isEqualToString:@"aliPay"]) {
  282. [self jsAliPay:message.body];
  283. }else if ([message.name isEqualToString:@"skipCameraWithParam"]) {
  284. [self jsSkipCameraWithParam:message.body];
  285. }else if ([message.name isEqualToString:@"skipAlbumWithParam"]) {
  286. [self jsSkipAlbumWithParam:message.body];
  287. }else if ([message.name isEqualToString:@"openActivityPage"]) {
  288. [self jsOpenActivityPage:message.body];
  289. }else if ([message.name isEqualToString:@"callPhone"]) {
  290. [self jsCallPhone:message.body];
  291. }else if ([message.name isEqualToString:@"openOtherAppLinks"]) {
  292. [self jsOpenOtherAppLinks:message.body];
  293. }else if ([message.name isEqualToString:@"inPurchasingVip"]) {
  294. [self jsInPurchasingVip:message.body];
  295. }else if ([message.name isEqualToString:@"wirteRight"]) {
  296. [self jsWirteRight:message.body];
  297. }else if ([message.name isEqualToString:@"clearRight"]) {
  298. [self jsClearRight:message.body];
  299. }else if ([message.name isEqualToString:@"savePic"]) {
  300. [self jsSavePic:message.body];
  301. }else if ([message.name isEqualToString:@"ocrVerifyService"]) {
  302. [self jsOcrVerifyService:message.body];
  303. }else if ([message.name isEqualToString:@"faceVerifyService"]) {
  304. [self jsFaceVerifyService:message.body];
  305. }else {
  306. }
  307. }
  308. #pragma mark - WKUIDelegate
  309. - (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(nullable NSString *)defaultText initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSString * _Nullable result))completionHandler
  310. {
  311. NSError *err = nil;
  312. NSData *dataFromString = [prompt dataUsingEncoding:NSUTF8StringEncoding];
  313. NSDictionary *paramdict = [NSJSONSerialization JSONObjectWithData:dataFromString options:NSJSONReadingMutableContainers error:&err];
  314. // NSLog(@"拦截%@",paramdict);
  315. if (!err){
  316. NSString *type = [paramdict objectForKey:@"jsName"];
  317. if (type && [type isEqualToString:@"getUserToken"]) {
  318. NSDictionary *dict = @{@"type":@"string",
  319. @"value":[self jsGetUserToken:paramdict]};
  320. completionHandler([self convertToJsonData:dict]);
  321. }else if (type && [type isEqualToString:@"getVersion"]) {
  322. NSDictionary *dict = @{@"type":@"string",
  323. @"value":[self jsGetVersion:paramdict]};
  324. completionHandler([self convertToJsonData:dict]);
  325. }else if (type && [type isEqualToString:@"checkNoticePermission"]) {
  326. NSDictionary *dict = @{@"type":@"int",
  327. @"value":[NSString stringWithFormat:@"%d",[self jsCheckNoticePermission:paramdict]]};
  328. completionHandler([self convertToJsonData:dict]);
  329. }else if (type && [type isEqualToString:@"getPushRid"]) {
  330. NSDictionary *dict = @{@"type":@"string",@"value":[self jsGetPushRid:paramdict]};
  331. completionHandler([self convertToJsonData:dict]);
  332. }else if (type && [type isEqualToString:@"isInstallWeixin"]) {
  333. NSDictionary *dict = @{@"type":@"int",
  334. @"value":[NSString stringWithFormat:@"%d",[self jsIsInstallWeixin:paramdict]]};
  335. completionHandler([self convertToJsonData:dict]);
  336. }else if (type && [type isEqualToString:@"getCipherText"]) {
  337. NSDictionary *dict = @{@"type":@"string",
  338. @"value":[self jsGetCipherText:paramdict]};
  339. completionHandler([self convertToJsonData:dict]);
  340. }
  341. else if (type && [type isEqualToString:@"getOtherPushRid"]) {
  342. NSDictionary *dict = @{@"type":@"string",@"value":[self jsGetOtherPushRid:paramdict]};
  343. completionHandler([self convertToJsonData:dict]);
  344. }else if (type && [type isEqualToString:@"getPhoneBrand"]) {
  345. NSDictionary *dict = @{@"type":@"string",
  346. @"value":[self jsGetPhoneBrand:paramdict]};
  347. completionHandler([self convertToJsonData:dict]);
  348. }else if (type && [type isEqualToString:@"readRight"]) {
  349. NSDictionary *dict = @{@"type":@"string",
  350. @"value":[self jsReadRight:paramdict]};
  351. completionHandler([self convertToJsonData:dict]);
  352. }else {
  353. completionHandler(@"");
  354. }
  355. }
  356. }
  357. //通过js alert 显示一个警告面板,调用原生会走此方法。
  358. - (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler
  359. {
  360. NSLog(@"显示一个JavaScript警告面板, message = %@",message);
  361. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:message preferredStyle:UIAlertControllerStyleAlert];
  362. [alertController addAction:[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  363. completionHandler();
  364. }]];
  365. [self presentViewController:alertController animated:YES completion:nil];
  366. }
  367. //通过 js confirm 显示一个确认面板,调用原生会走此方法。
  368. - (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL result))completionHandler
  369. {
  370. NSLog(@"运行JavaScript确认面板, message = %@", message);
  371. UIAlertController *action = [UIAlertController alertControllerWithTitle:@"温馨提示" message:message preferredStyle:UIAlertControllerStyleAlert];
  372. [action addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  373. completionHandler(NO);
  374. }] ];
  375. [action addAction:[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  376. completionHandler(YES);
  377. }]];
  378. [self presentViewController:action animated:YES completion:nil];
  379. }
  380. #pragma mark - OC调JS交互
  381. -(void)isExitCallToJS:(NSString *)jsStr withMethodName:(NSString *)name{
  382. NSString *jsName = [NSString stringWithFormat:@"function exist(){return !window['%@']};exist()",name];
  383. [_webView evaluateJavaScript:jsName completionHandler:^(id _Nullable result, NSError * _Nullable error) {
  384. // NSLog(@"是否存在 result:%@,error:%@",result,error);
  385. if ([result intValue]==0) {
  386. [self executeCallJS:jsStr];
  387. }else {
  388. NSLog(@"不存在-不存在-不存在-%@",jsStr);
  389. }
  390. }];
  391. }
  392. -(void)executeCallJS:(NSString *)jsStr {
  393. // NSLog(@"OC调JS交互%@:",jsStr);
  394. [_webView evaluateJavaScript:jsStr completionHandler:^(id _Nullable result, NSError * _Nullable error) {
  395. if (error!=nil) {
  396. NSLog(@"result:%@,error:%@",result,error);
  397. // [[LXViewControllerManager shareViewControllerManager]showAlertViewWithMessage: jsStr];
  398. [[GlobalData shareInstance] addOnePlistData:@{
  399. @"detail":[[self stringByEvaluatingJavaScriptFromString:@"document.location.href"] stringByAppendingString:[NSString stringWithFormat:@"\nJS异常方法:%@\n%@",jsStr,[error description]]],
  400. @"reqTime":[NSNumber numberWithInt:0],
  401. }];
  402. }
  403. }];
  404. }
  405. - (void)viewDidLoad {
  406. [super viewDidLoad];
  407. // Do any additional setup after loading the view.
  408. NSLog(@"我的初始化");
  409. self.view.backgroundColor = [UIColor whiteColor];
  410. [self.view addSubview:self.webView];
  411. [self.view addSubview:self.progressView];
  412. [self webViewFirstRequest];
  413. [[AFNetworkReachabilityManager sharedManager] startMonitoring];
  414. [self initNotification];
  415. self.recognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(paningGestureReceive:)];
  416. [self.recognizer delaysTouchesBegan];
  417. [self.view addGestureRecognizer:self.recognizer];
  418. //监听底部栏
  419. [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(bottomFourListening) userInfo:nil repeats:YES];
  420. }
  421. -(void)bottomFourListening {
  422. if(self.tabBarController.selectedIndex == 3) {
  423. [self judgeIsHiddenBottom];
  424. }
  425. }
  426. #pragma mark - WKNavigationDelegate
  427. /* 页面加载完成 */
  428. - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
  429. NSLog(@"-----页面加载完成%@",webView.URL.absoluteString);
  430. [self judgeIsHiddenBottom];
  431. [self removeNoNetViews];
  432. [self removeFailNetViews];
  433. [[LXViewControllerManager shareViewControllerManager] hideHud];
  434. [self.webView evaluateJavaScript:@"document.documentElement.style.webkitTouchCallout='none';" completionHandler:nil];
  435. // [self.webView evaluateJavaScript:@"document.documentElement.style.webkitUserSelect='none';"completionHandler:nil];
  436. //写数据
  437. // [self writeWKWebData:webView.URL];
  438. }
  439. -(void)writeWKWebData:(NSURL *)url {
  440. //得到NSData 数据
  441. NSData *dataContent = [NSData dataWithContentsOfURL:url];
  442. //NSURLCache 实例化
  443. NSURLCache *cache = [NSURLCache sharedURLCache];
  444. //得到相应
  445. NSURLResponse *response = [[NSURLResponse alloc]initWithURL:url MIMEType:@"text/html" expectedContentLength:0 textEncodingName:@"UTF-8"];
  446. //得到CacheURLResponse
  447. NSCachedURLResponse *cacheResponse = [[NSCachedURLResponse alloc]initWithResponse:response data:dataContent];
  448. //进行存储
  449. [cache storeCachedResponse:cacheResponse forRequest:[NSURLRequest requestWithURL:url]];
  450. }
  451. // 页面开始加载时调用
  452. - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{
  453. self.recognizer.enabled = NO;
  454. }
  455. // 当内容开始返回时调用
  456. - (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation{
  457. }
  458. // 页面加载失败时调用
  459. - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(nonnull NSError *)error{
  460. //加载失败 有网络-弹出页面 , 无网络-记录标记
  461. if ([ZKMethod judegeNetworkIsAvailable]) {
  462. //弹出页面
  463. NSLog(@"页面加载失败-有网络");
  464. [self addFailNetViews];
  465. }else {
  466. //记录标记
  467. NSLog(@"页面加载失败-无网络");
  468. isExistNoNewWork = YES;
  469. }
  470. self.recognizer.enabled = YES;
  471. [[GlobalData shareInstance] addOnePlistData:@{
  472. @"detail":[[self stringByEvaluatingJavaScriptFromString:@"document.location.href"] stringByAppendingString:[NSString stringWithFormat:@"\n%@",[error description]]],
  473. @"reqTime":[NSNumber numberWithInt:0],
  474. }];
  475. }
  476. #pragma mark *****JS与OC交互
  477. #pragma mark - WKScriptMessageHandler JS调OC交互
  478. -(void)jsLoginByWeixin:(NSDictionary *)dict {
  479. if ([LXUserDefaults isInstallWeiXin] != 1) { // 没有安装微信 不走友盟
  480. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"微信登录失败,没有安装微信" delay:1.5];
  481. return;
  482. }
  483. [[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_WechatSession currentViewController:self completion:^(id result, NSError *error) {
  484. UMSocialUserInfoResponse *resp = result;
  485. [self dealWXDic:(NSDictionary *)resp.originalResponse];
  486. [[LXViewControllerManager shareViewControllerManager] hideHud];
  487. }];
  488. }
  489. // 处理微信登录获取到的数据
  490. -(void)dealWXDic:(NSDictionary *)dictionary{
  491. [[LXViewControllerManager shareViewControllerManager] showHudText:nil];
  492. //如果获取到用户信息,即用户点击了“登录”,则进行用户信息获取
  493. if (dictionary.count > 0) {
  494. NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:dictionary];
  495. if (dic) {
  496. [dic removeObjectForKey:@"privilege"];
  497. [dic removeObjectForKey:@"language"];
  498. double currDouble = [[NSDate date] timeIntervalSince1970];
  499. [dic setObject:[NSNumber numberWithLong:(long)currDouble] forKey:@"createtime"];
  500. // 拼接标志位
  501. NSString *sign = [NSString stringWithFormat:@"city=%@&country=%@&createtime=%@&headimgurl=%@&nickname=%@&openid=%@&province=%@&sex=%@&unionid=%@", dic[@"city"], dic[@"country"], dic[@"createtime"], dic[@"headimgurl"], dic[@"nickname"], dic[@"openid"], dic[@"province"],dic[@"sex"],dic[@"unionid"]];
  502. sign = [LXMD5 md532BitLower:sign];
  503. [dic setObject:sign forKey:@"sign"];
  504. NSString *endStr = [[LXViewControllerManager shareViewControllerManager] getJsonStr:dic];
  505. NSData *data = [endStr dataUsingEncoding:NSUTF8StringEncoding];
  506. endStr = [data base64EncodedStringWithOptions:0];
  507. [self isExitCallToJS:[NSString stringWithFormat:@"loginByWeixinCallBack('%@')", endStr] withMethodName:@"loginByWeixinCallBack"];
  508. }
  509. }
  510. }
  511. -(void)jsShare:(NSDictionary *)dict {
  512. NSString *type = [NSString stringWithFormat:@"%@",dict[@"type"]];
  513. NSString *title = [NSString stringWithFormat:@"%@",dict[@"title"]];
  514. NSString *content = [NSString stringWithFormat:@"%@",dict[@"content"]];
  515. NSString *link = [NSString stringWithFormat:@"%@",dict[@"link"]];
  516. UMSocialPlatformType shareType;
  517. if ([type intValue] == 1) { // 微信好友
  518. shareType = UMSocialPlatformType_WechatSession;
  519. }else if ([type intValue] == 2){ /// qq好友
  520. shareType = UMSocialPlatformType_QQ;
  521. }else if ([type intValue] == 3){ // 朋友圈
  522. shareType = UMSocialPlatformType_WechatTimeLine;
  523. }else{
  524. shareType = UMSocialPlatformType_WechatSession;
  525. }
  526. if ([type intValue] == 1 || [type intValue] == 3) {
  527. if ([LXUserDefaults isInstallWeiXin] != 1) {
  528. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"没有安装微信" delay:1.5];
  529. return;
  530. }
  531. }
  532. if ([type intValue] == 2) {
  533. if (![[UMSocialManager defaultManager] isInstall:UMSocialPlatformType_QQ]) {
  534. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"没有安装QQ" delay:1.5];
  535. return;
  536. }
  537. }
  538. //创建分享消息对象
  539. UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
  540. //创建网页内容对象
  541. UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:title descr:content thumImage:[UIImage imageNamed:@"logo"]];
  542. //设置网页地址
  543. shareObject.webpageUrl = link;
  544. messageObject.shareObject = shareObject;
  545. //调用分享接口
  546. [[UMSocialManager defaultManager] shareToPlatform:shareType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
  547. NSLog(@"%@",error);
  548. if (error) {
  549. if (error.userInfo[@"message"] && [error.userInfo[@"message"] containsString:@"Operation is cancel"]) {
  550. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"取消分享" delay:1];
  551. }else{
  552. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:error.userInfo[@"message"] delay:1];
  553. }
  554. [self isExitCallToJS:[NSString stringWithFormat:@"shareCallBack('%@','%@')",type,@"0"] withMethodName:@"shareCallBack"];
  555. }else{
  556. if ([data isKindOfClass:[UMSocialShareResponse class]]) {
  557. [self isExitCallToJS:[NSString stringWithFormat:@"shareCallBack('%@','%@')",type,@"1"] withMethodName:@"shareCallBack"];
  558. }else{
  559. UMSocialLogInfo(@"response data is %@",data);
  560. }
  561. }
  562. }];
  563. }
  564. -(void)jsSaveUserToken:(NSDictionary *)dict{
  565. [[LXViewControllerManager shareViewControllerManager] hideHud];
  566. [LXUserDefaults saveToken:[NSString stringWithFormat:@"%@",dict[@"token"]]];
  567. }
  568. -(NSString *)jsGetUserToken:(NSDictionary *)dict{
  569. return [LXUserDefaults token];
  570. }
  571. -(void)jsRemoveUserToken:(NSDictionary *)dict{
  572. [LXUserDefaults clearAll];
  573. }
  574. -(int)jsCheckNoticePermission:(NSDictionary *)dict{
  575. return [LXUserDefaults notifyState];
  576. }
  577. // 跳转到系统设置
  578. -(void)jsOpenSystemNotification:(NSDictionary *)dict{
  579. self.updateNotify = YES;
  580. [[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
  581. }
  582. // 获取推送id
  583. -(NSString *)jsGetPushRid:(NSDictionary *)dict{
  584. return [LXUserDefaults registrationID];
  585. }
  586. // 打开新页面 加载新web
  587. -(void)JsOpenExternalLink:(NSDictionary *)dict{
  588. NSString *url = [NSString stringWithFormat:@"%@",dict[@"url"]];
  589. NSString *title = [NSString stringWithFormat:@"%@",dict[@"title"]];
  590. if (url) {
  591. if ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable || [AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusUnknown) {
  592. }
  593. JYWKNewWebController *ctr = [[JYWKNewWebController alloc] init];
  594. ctr.url = url;
  595. if (!title || [title isEqualToString:@""]||[title isEqualToString:@"undefined"]) {
  596. ctr.titleShow = nil;
  597. }else{
  598. ctr.titleShow = title;
  599. }
  600. kMainQueue(^{
  601. [self presentViewController:ctr animated:NO completion:nil];
  602. });
  603. }
  604. }
  605. // 获取当前版本号
  606. -(NSString *)jsGetVersion:(NSDictionary *)dict{
  607. return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
  608. }
  609. -(void)jsAlert:(NSDictionary *)dict{
  610. [[LXViewControllerManager shareViewControllerManager] showAlertViewWithMessage:[NSString stringWithFormat:@"%@",dict[@"content"]]];
  611. }
  612. -(int)jsIsInstallWeixin:(NSDictionary *)dict{
  613. return [LXUserDefaults isInstallWeiXin];
  614. }
  615. -(NSString *)jsGetCipherText:(NSDictionary *)dict{
  616. NSDictionary *objDict = [NSDictionary dictionaryWithDictionary:dict[@"arguments"]];
  617. NSString *phone = [NSString stringWithFormat:@"%@",objDict[@"phone"]];
  618. NSDate *date=[NSDate date];
  619. NSDateFormatter *format1=[[NSDateFormatter alloc] init];
  620. [format1 setDateFormat:@"yyyyMMddhhmmss"];
  621. NSString *dateStr;
  622. dateStr=[format1 stringFromDate:date];
  623. NSString *content = [[NSString stringWithFormat:@"%@_%@",phone,dateStr] stringByAppendingString:[NSString stringWithFormat:@"_%@",[LXMD5 md532BitLower:[NSString stringWithFormat:@"%@&%@",phone,dateStr]]]];
  624. NSData *contentData = [content dataUsingEncoding:NSUTF8StringEncoding];
  625. NSUInteger dataLength = contentData.length;
  626. // 为结束符'\\0' +1
  627. char keyPtr[new_kKeySize_4 + 1];
  628. memset(keyPtr, 0, sizeof(keyPtr));
  629. [new_AesKey_4 getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
  630. // 密文长度 <= 明文长度 + BlockSize
  631. size_t encryptSize = dataLength + kCCBlockSizeAES128;
  632. void *encryptedBytes = malloc(encryptSize);
  633. size_t actualOutSize = 0;
  634. NSData *initVector = [new_kInitVector_4 dataUsingEncoding:NSUTF8StringEncoding];
  635. CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt,
  636. kCCAlgorithmAES,
  637. kCCOptionPKCS7Padding, // 系统默认使用 CBC,然后指明使用 PKCS7Padding
  638. keyPtr,
  639. new_kKeySize_4,
  640. initVector.bytes,
  641. contentData.bytes,
  642. dataLength,
  643. encryptedBytes,
  644. encryptSize,
  645. &actualOutSize);
  646. if (cryptStatus == kCCSuccess) {
  647. // 对加密后的数据进行 base64 编码
  648. return [[NSData dataWithBytesNoCopy:encryptedBytes length:actualOutSize] base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
  649. }
  650. free(encryptedBytes);
  651. return nil;
  652. }
  653. -(void)jsHiddenBottom:(NSDictionary *)dict{
  654. if(self.tabBarController.selectedIndex == 3) {
  655. if([[NSString stringWithFormat:@"%@",dict[@"hidden"]] integerValue]==0) {
  656. [self hideTabBar];
  657. [self hiddenMethodTabBar];
  658. }else {
  659. [self showTabBar];
  660. [self showMethodTabBar];
  661. }
  662. }
  663. }
  664. -(void)jsCheckLab:(NSDictionary *)dict {
  665. [[NSNotificationCenter defaultCenter] postNotificationName:RefreshNonCurVC object:nil userInfo:nil];
  666. }
  667. //js方法登录成功
  668. -(void)jsLoginSuccess:(NSDictionary *)dict {
  669. NSLog(@"mine登录成功提示");
  670. NSString *status = [NSString stringWithFormat:@"%@",dict[@"status"]];
  671. [GlobalData shareInstance].isReLogin = YES;
  672. if([status isEqualToString:@"S"]) {
  673. kMainQueue(^{
  674. [[NSNotificationCenter defaultCenter] postNotificationName:RefreshAllVC object:nil userInfo:nil];
  675. AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  676. JYTabBarController *tab = (JYTabBarController *)delegate.window.rootViewController;
  677. tab.selectedIndex = 0;
  678. //
  679. });
  680. }else {
  681. }
  682. //弹出页面
  683. if ([GlobalData shareInstance].isPasteLogin) {
  684. [GlobalData shareInstance].isPasteLogin = NO;
  685. NSString *content = [UIPasteboard generalPasteboard].string;
  686. [self popPasteVIew:content];
  687. }
  688. }
  689. -(void)jsBackUrl:(NSDictionary *)dict {
  690. NSString *status = [NSString stringWithFormat:@"%@",dict[@"status"]];
  691. NSLog(@"sub返回");
  692. if([status isEqualToString:@"H"]) {
  693. //测试返回首页
  694. kMainQueue(^{
  695. [[NSNotificationCenter defaultCenter] postNotificationName:RefreshAllVC object:nil userInfo:nil];
  696. AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  697. JYTabBarController *tab = (JYTabBarController *)delegate.window.rootViewController;
  698. tab.selectedIndex = 0;
  699. });
  700. }
  701. }
  702. -(void)jsClearPushMessage:(NSDictionary *)dict {
  703. kMainQueue(^{
  704. [[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
  705. [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
  706. });
  707. }
  708. -(void)jsHideRedSpotOnMenu:(NSDictionary *)dict {
  709. NSString *menu = [NSString stringWithFormat:@"%@",dict[@"menu"]];
  710. if([menu isEqualToString:@"subscribe"]) {
  711. kMainQueue(^{
  712. [self.tabBarController.tabBar hideBadgeOnItemIndex:1];
  713. });
  714. }
  715. if([menu isEqualToString:@"my"]) {
  716. kMainQueue(^{
  717. [self.tabBarController.tabBar hideBadgeOnItemIndex:3];
  718. });
  719. }
  720. }
  721. -(void)jsShowRedSpotOnMenu:(NSDictionary *)dict {
  722. NSString *menu = [NSString stringWithFormat:@"%@",dict[@"menu"]];
  723. if([menu isEqualToString:@"subscribe"]) {
  724. kMainQueue(^{
  725. [self.tabBarController.tabBar showBadgeOnItemIndex:1];
  726. });
  727. }
  728. if([menu isEqualToString:@"my"]) {
  729. kMainQueue(^{
  730. [self.tabBarController.tabBar showBadgeOnItemIndex:3];
  731. });
  732. }
  733. }
  734. -(void)jsWxPay:(NSDictionary *)dict {
  735. NSString *jsonString = [NSString stringWithFormat:@"%@",dict[@"order"]];
  736. if ([LXUserDefaults isInstallWeiXin] != 1) { // 没有安装wx
  737. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"请先安装微信再进行支付!" delay:1.5];
  738. return;
  739. }
  740. NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
  741. NSError *err;
  742. NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
  743. if(err) {
  744. NSLog(@"json解析失败:%@",err);
  745. return;
  746. }
  747. //吊起微信
  748. PayReq *request = [[PayReq alloc] init] ;
  749. request.openID = dic[@"Appid"];
  750. request.partnerId = dic[@"Partnerid"];
  751. request.prepayId= dic[@"Prepayid"];
  752. request.package = @"Sign=WXPay";
  753. request.nonceStr= dic[@"Noncestr"];
  754. request.timeStamp= [dic[@"Timestamp"] intValue];
  755. request.sign= dic[@"Sign"];
  756. kMainQueue(^{
  757. [WXApi sendReq:request];
  758. });
  759. }
  760. -(void)jsAliPay:(NSDictionary *)dict {
  761. NSString *order = [NSString stringWithFormat:@"%@",dict[@"order"]];
  762. kMainQueue(^{
  763. [[AlipaySDK defaultService] payOrder:order fromScheme:@"jianyuiosapp" callback:nil];
  764. });
  765. }
  766. -(NSString *)jsGetOtherPushRid:(NSDictionary *)dict {
  767. return [LXUserDefaults deviceToken];
  768. }
  769. -(NSString *)jsGetPhoneBrand:(NSDictionary *)dict {
  770. UIDevice *device = [UIDevice currentDevice];
  771. return device.platformString;
  772. }
  773. //拍照上传图片
  774. -(void)jsSkipCameraWithParam:(NSDictionary *)dict {
  775. [GlobalData shareInstance].isSkipPath = [NSString stringWithFormat:@"%@",dict[@"type"]];
  776. UIImagePickerController *picker = [[UIImagePickerController alloc] init];
  777. picker.delegate = self;
  778. picker.allowsEditing = YES;
  779. picker.sourceType = UIImagePickerControllerSourceTypeCamera;
  780. dispatch_async(dispatch_get_main_queue(), ^{
  781. [self presentViewController:picker animated:YES completion:nil];
  782. });
  783. }
  784. //相册选择照片
  785. -(void)jsSkipAlbumWithParam:(NSDictionary *)dict {
  786. [GlobalData shareInstance].isSkipPath = [NSString stringWithFormat:@"%@",dict[@"type"]];
  787. UIImagePickerController *picker = [[UIImagePickerController alloc] init];
  788. picker.delegate = self;
  789. picker.allowsEditing = YES;
  790. picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  791. dispatch_async(dispatch_get_main_queue(), ^{
  792. [self presentViewController:picker animated:YES completion:nil];
  793. });
  794. }
  795. -(void)jsOpenActivityPage:(NSDictionary *)dict {
  796. NSDictionary * infoDic = @{@"url":[NSString stringWithFormat:@"%@",dict[@"url"]],
  797. @"rectype":[NSString stringWithFormat:@"%@",dict[@"rectype"]],
  798. @"openid":[NSString stringWithFormat:@"%@",dict[@"openid"]],
  799. };
  800. //post请求
  801. NSLog(@"%@",[NSString stringWithFormat:@"%@jyapp/free/message/receive",kHost]);
  802. [[LXNetworkManager shareLXNetworkManager]postWithURLStr:[NSString stringWithFormat:@"%@jyapp/free/message/receive",kHost] parameters:infoDic progress:^(NSProgress *progress) {
  803. NSLog(@"成功:%@",progress);
  804. } success:^(id responseObject) {
  805. NSLog(@"responseObject=%@",responseObject);
  806. } failure:^(NSError *error) {
  807. NSLog(@"error=%@",error);
  808. [[GlobalData shareInstance] addOnePlistData:@{
  809. @"detail":[NSString stringWithFormat:@"message/receive接口:%@",[error description]],
  810. @"reqTime":[NSNumber numberWithInt:0],
  811. }];
  812. }];
  813. }
  814. //拨打电话
  815. -(void)jsCallPhone:(NSDictionary *)dict {
  816. NSString *phone = [NSString stringWithFormat:@"%@",dict[@"phone"]];
  817. NSMutableString *tel = [[NSMutableString alloc]initWithFormat:@"telprompt://%@",phone];
  818. if (@available(iOS 10.0, *)) {
  819. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:tel] options:@{} completionHandler:^(BOOL success) {
  820. }];
  821. } else {
  822. // Fallback on earlier versions
  823. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:tel]];
  824. }
  825. }
  826. //打开其他app 抖音+快手
  827. -(void)jsOpenOtherAppLinks:(NSDictionary *)dict {
  828. //测试跳转抖音--快手 @"gifshow://" @"snssdk1128://"
  829. NSString *appLink = [NSString stringWithFormat:@"%@",dict[@"appLink"]];
  830. NSString *appName = [NSString stringWithFormat:@"%@",dict[@"appName"]];
  831. NSLog(@"appName:%@",appName);
  832. NSURL *url = [NSURL URLWithString:appLink];
  833. if ([[UIApplication sharedApplication] canOpenURL:url]) {
  834. if ([[UIApplication sharedApplication] respondsToSelector:@selector(openURL:options:completionHandler:)]) {
  835. //iOS 10.0+
  836. NSLog(@"iOS 10+");
  837. if (@available(iOS 10.0, *)) {
  838. [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
  839. if (!success) {
  840. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:appName delay:2];
  841. }
  842. }];
  843. } else {
  844. // Fallback on earlier versions
  845. [[UIApplication sharedApplication] openURL:url];
  846. }
  847. }else{
  848. NSLog(@"iOS 2~10");
  849. //iOS 2~10
  850. [[UIApplication sharedApplication] openURL:url];
  851. }
  852. }else{
  853. //一般是没有安装
  854. NSLog(@"跳转下载app链接");
  855. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:appName delay:2];
  856. }
  857. }
  858. #pragma mark *****人脸核身
  859. //ocr验证
  860. -(void)jsOcrVerifyService:(NSDictionary *)dict{
  861. NSLog(@"ocr:%@",dict);
  862. NSString *orderNo = [NSString stringWithFormat:@"%@",dict[@"orderNo"]];
  863. NSString *nonce = [NSString stringWithFormat:@"%@",dict[@"nonce"]];
  864. NSString *userId = [NSString stringWithFormat:@"%@",dict[@"userId"]];
  865. NSString *sign = [NSString stringWithFormat:@"%@",dict[@"sign"]];
  866. kMainQueue((^{
  867. WBOCRConfig *config = [WBOCRConfig sharedConfig];
  868. config.needRecordVideo = NO;
  869. config.SDKType = WBOCRSDKTypeIDCardNormal; // 身份证两面识别
  870. [[WBOCRService sharedService] startOCRServiceWithConfig:config version:@"1.0.0" appId:OCRAPPID nonce:nonce userId:userId sign:sign orderNo:orderNo startSucceed:^{
  871. /** SDK服务拉起成功回调 */
  872. NSLog(@"启动SDK成功!!!");
  873. } recognizeSucceed:^(id _Nonnull resultModel, id _Nullable extension) {
  874. /** SDK本次识别成功回调 */
  875. NSLog(@"SDK识别成功!!!");
  876. //调用js - 告知成功
  877. NSString *textJS = [NSString stringWithFormat:@"ocrVerifyResult('%@')",orderNo];
  878. [self isExitCallToJS:textJS withMethodName:@"ocrVerifyResult"];
  879. } failed:^(NSError * _Nonnull error, id _Nullable extension) {
  880. /** SDK异常回调 */
  881. NSLog(@"识别出错!!!"); //200101 用户取消操作
  882. //弹出页面
  883. if (error.code == 200101) {
  884. self.verifyMsgView.descTitle = @"您取消了身份验证";
  885. }else {
  886. self.verifyMsgView.descTitle = @"身份验证失败";
  887. }
  888. [self.verifyMsgView show];
  889. NSString *textJS = [NSString stringWithFormat:@"ocrVerifyResult('%@')",@""];
  890. [self isExitCallToJS:textJS withMethodName:@"ocrVerifyResult"];
  891. }];
  892. }));
  893. }
  894. //人脸核身
  895. -(void)jsFaceVerifyService:(NSDictionary *)dict {
  896. NSLog(@"face:%@",dict);
  897. NSString *orderNo = [NSString stringWithFormat:@"%@",dict[@"orderNo"]];
  898. NSString *nonce = [NSString stringWithFormat:@"%@",dict[@"nonce"]];
  899. NSString *userId = [NSString stringWithFormat:@"%@",dict[@"userId"]];
  900. NSString *sign = [NSString stringWithFormat:@"%@",dict[@"sign"]];
  901. NSString *faceId = [NSString stringWithFormat:@"%@",dict[@"faceId"]];
  902. kMainQueue((^{
  903. [WBFaceVerifyCustomerService sharedInstance].delegate = self;
  904. WBFaceVerifySDKConfig *config = [WBFaceVerifySDKConfig sdkConfig];
  905. config.recordVideo = NO;
  906. config.theme = WBFaceVerifyThemeDarkness;
  907. [[WBFaceVerifyCustomerService sharedInstance] loginInLiveCheckAndCompareWithSourceImageService:userId nonce:nonce sign:sign appid:OCRAPPID orderNo:orderNo apiVersion:@"1.0.0" licence:LICENCE faceType:WBFaceVerifyLivingType_Action faceId:faceId sdkConfig:config success:^{
  908. } failure:^(WBFaceError * _Nonnull error) {
  909. }];
  910. }));
  911. }
  912. #pragma mark - WBFaceVerifyCustomerServiceDelegate
  913. -(void)wbfaceVerifyCustomerServiceDidFinishedWithFaceVerifyResult:(WBFaceVerifyResult *)faceVerifyResult{
  914. if (faceVerifyResult.isSuccess) {
  915. NSLog(@"活体检测成功:%@",faceVerifyResult.orderNo);
  916. NSString *textJS = [NSString stringWithFormat:@"faceVerifyResult('%@')",faceVerifyResult.orderNo];
  917. [self isExitCallToJS:textJS withMethodName:@"faceVerifyResult"];
  918. self.verifyMsgView.descTitle = @"活体检测成功";
  919. [self.verifyMsgView show];
  920. }else {
  921. NSLog(@"活体检测失败");
  922. self.verifyMsgView.descTitle = @"活体检测失败";
  923. [self.verifyMsgView show];
  924. NSString *textJS = [NSString stringWithFormat:@"faceVerifyResult('%@')",@""];
  925. [self isExitCallToJS:textJS withMethodName:@"faceVerifyResult"];
  926. }
  927. }
  928. //保存图片到相册
  929. #pragma mark 保存图片
  930. -(void)jsSavePic:(NSDictionary *)dict {
  931. NSString *base64ImgData = [NSString stringWithFormat:@"%@",dict[@"imgbase64"]];
  932. NSData *data = [[NSData alloc]initWithBase64EncodedString:base64ImgData options:NSDataBase64DecodingIgnoreUnknownCharacters];
  933. UIImage *saveImg = [UIImage imageWithData:data];
  934. UIImageWriteToSavedPhotosAlbum(saveImg, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
  935. }
  936. #pragma mark 系统的完成保存图片的方法
  937. - (void)image: (UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo
  938. {
  939. NSString *msg = nil ;
  940. if (error != NULL) {
  941. msg = @"保存图片失败" ;
  942. } else {
  943. msg = @"保存图片成功" ;
  944. }
  945. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:msg delay:1];
  946. }
  947. #pragma mark 粘贴板
  948. -(void)jsWirteRight:(NSDictionary *)dict {
  949. NSString *txt = [NSString stringWithFormat:@"%@",dict[@"txt"]];
  950. [[UIPasteboard generalPasteboard]setString:txt];
  951. }
  952. -(void)jsClearRight:(NSDictionary *)dict {
  953. //清粘贴板数据
  954. [[UIPasteboard generalPasteboard]setString:@""];
  955. }
  956. -(NSString *)jsReadRight:(NSDictionary *)dict {
  957. NSString *content = [UIPasteboard generalPasteboard].string;
  958. return content;
  959. }
  960. //内购VIP
  961. -(void)jsInPurchasingVip:(NSDictionary *)dict {
  962. NSString *productid = [NSString stringWithFormat:@"%@",dict[@"productid"]];
  963. //产品id
  964. if ([productid isEqualToString:@""]) {
  965. NSLog(@"订单号 有问题");
  966. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"订单号异常,请重试" delay:1];
  967. return;
  968. }
  969. [[LXViewControllerManager shareViewControllerManager] showHudText:@"苹果验证中,请稍候"];
  970. if([SKPaymentQueue canMakePayments]){
  971. [self requestProductData:productid];
  972. }else{
  973. [[LXViewControllerManager shareViewControllerManager] hideHud];
  974. }
  975. }
  976. //去苹果服务器请求商品
  977. - (void)requestProductData:(NSString *)type {
  978. NSArray *product = [[NSArray alloc] initWithObjects:type,nil];
  979. NSSet *nsset = [NSSet setWithArray:product];
  980. SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:nsset];
  981. request.delegate = self;
  982. [request start];
  983. }
  984. - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
  985. NSArray *myProduct = response.products;
  986. if (myProduct.count == 0) {
  987. NSLog(@"无法获取产品信息,购买失败。");
  988. [[LXViewControllerManager shareViewControllerManager]showHudOnlyText:@"暂时未获取到产品信息,请重试" delay:1];
  989. return;
  990. }
  991. SKPayment * payment = [SKPayment paymentWithProduct:myProduct[0]];
  992. [[SKPaymentQueue defaultQueue] addPayment:payment];
  993. }
  994. #pragma mark *****其他方法
  995. -(void)judgeIsHiddenBottom {
  996. if(self.tabBarController.selectedIndex == 3) {
  997. NSString *current_url = [self stringByEvaluatingJavaScriptFromString:@"document.location.href"];
  998. if([current_url isEqualToString:[NSString stringWithFormat:@"%@jyapp/free/me",kHost]]){
  999. [self showTabBar];
  1000. [self showMethodTabBar];
  1001. }else {
  1002. [self hideTabBar];
  1003. [self hiddenMethodTabBar];
  1004. }
  1005. }
  1006. }
  1007. - (void)hideTabBar {
  1008. kMainQueue(^{
  1009. if (self.tabBarController.tabBar.hidden == YES) {
  1010. return;
  1011. }
  1012. UIView *contentView;
  1013. if ( [[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] )
  1014. contentView = [self.tabBarController.view.subviews objectAtIndex:1];
  1015. else
  1016. contentView = [self.tabBarController.view.subviews objectAtIndex:0];
  1017. contentView.frame = CGRectMake(contentView.bounds.origin.x, contentView.bounds.origin.y, contentView.bounds.size.width, contentView.bounds.size.height + self.tabBarController.tabBar.frame.size.height);
  1018. self.tabBarController.tabBar.hidden = YES;
  1019. });
  1020. }
  1021. - (void)showTabBar{
  1022. kMainQueue(^{
  1023. if (self.tabBarController.tabBar.hidden == NO)
  1024. {
  1025. return;
  1026. }
  1027. UIView *contentView;
  1028. if ([[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]])
  1029. contentView = [self.tabBarController.view.subviews objectAtIndex:1];
  1030. else
  1031. contentView = [self.tabBarController.view.subviews objectAtIndex:0];
  1032. contentView.frame = CGRectMake(contentView.bounds.origin.x, contentView.bounds.origin.y, contentView.bounds.size.width, contentView.bounds.size.height - self.tabBarController.tabBar.frame.size.height);
  1033. self.tabBarController.tabBar.hidden = NO;
  1034. });
  1035. }
  1036. - (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script
  1037. {
  1038. __block NSString *resultString = nil;
  1039. __block BOOL finished = NO;
  1040. [self.webView evaluateJavaScript:script completionHandler:^(id result, NSError *error) {
  1041. if (error == nil) {
  1042. if (result != nil) {
  1043. resultString = [NSString stringWithFormat:@"%@", result];
  1044. }
  1045. } else {
  1046. NSLog(@"evaluateJavaScript error : %@", error.localizedDescription);
  1047. }
  1048. finished = YES;
  1049. }];
  1050. while (!finished) {
  1051. [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
  1052. }
  1053. return resultString;
  1054. }
  1055. -(void)hiddenMethodTabBar
  1056. {
  1057. kMainQueue(^{
  1058. if (iPhoneX) {
  1059. if (@available(iOS 11.0, *)) {
  1060. self.webView.frame = CGRectMake(0, 0, WIDTH, HEIGHT);
  1061. }
  1062. }else {
  1063. self.webView.frame = CGRectMake(0, -STATUS_BAR_HEIGHT, WIDTH, HEIGHT+STATUS_BAR_HEIGHT);
  1064. }
  1065. });
  1066. }
  1067. -(void)showMethodTabBar
  1068. {
  1069. kMainQueue(^{
  1070. if (iPhoneX) {
  1071. if (@available(iOS 11.0, *)) {
  1072. self.webView.frame = CGRectMake(0, 0, WIDTH, HEIGHT-TAB_BAR_HEIGHT);
  1073. }
  1074. }else {
  1075. self.webView.frame = CGRectMake(0, -STATUS_BAR_HEIGHT, WIDTH, HEIGHT-TAB_BAR_HEIGHT+STATUS_BAR_HEIGHT);
  1076. }
  1077. });
  1078. }
  1079. //取消获取照片
  1080. - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
  1081. {
  1082. dispatch_async(dispatch_get_main_queue(), ^{
  1083. [picker dismissViewControllerAnimated:YES completion:^{
  1084. [self uploadUrl:@""];
  1085. }];
  1086. });
  1087. }
  1088. //上传图片
  1089. -(void)uploadPic:(NSData *)data
  1090. {
  1091. NSString *isPath = @"courseFile";
  1092. if (![[GlobalData shareInstance].isSkipPath isEqualToString:@""]) {
  1093. isPath = [GlobalData shareInstance].isSkipPath;
  1094. }
  1095. NSDictionary * body = @{@"type":isPath};
  1096. AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
  1097. //ContentType设置
  1098. manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html",@"image/jpeg",@"image/png",@"application/octet-stream",@"text/json",@"text/plain",nil];
  1099. manager.responseSerializer= [AFHTTPResponseSerializer serializer];
  1100. manager.requestSerializer = [AFHTTPRequestSerializer serializer];
  1101. manager.requestSerializer.timeoutInterval = 15.0f;
  1102. [manager POST:[NSString stringWithFormat:@"%@jyapp/filemanage/upload",kHost] parameters:body constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
  1103. //上传的参数(上传图片,以文件流的格式)
  1104. [formData appendPartWithFileData:data
  1105. name:isPath
  1106. fileName:[isPath stringByAppendingFormat:@".jpeg"]
  1107. mimeType:@"image/jpeg"];
  1108. } progress:^(NSProgress * _Nonnull uploadProgress) {
  1109. CGFloat progress = 100.0 * uploadProgress.completedUnitCount / uploadProgress.totalUnitCount;
  1110. NSLog(@"%.2lf%%", progress);
  1111. } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
  1112. //请求成功的block回调
  1113. NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
  1114. NSLog(@"上传成功%@",dic);
  1115. if ([dic[@"msg"] isEqualToString:@"ssss"]) {
  1116. [self uploadUrl:dic[@"url"]];
  1117. }else{
  1118. [self uploadUrl:@""];
  1119. }
  1120. } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
  1121. NSLog(@"上传失败%@",error);
  1122. [self uploadUrl:@""];
  1123. [[GlobalData shareInstance] addOnePlistData:@{
  1124. @"detail":@"上传图片接口",
  1125. @"reqTime":[NSNumber numberWithInt:0],
  1126. }];
  1127. }];
  1128. }
  1129. -(void)uploadUrl:(NSString *)url {
  1130. NSString *textJS = [NSString new];
  1131. NSString *methodJS = [NSString new];
  1132. if ([url isEqualToString:@""]) {
  1133. textJS = @"hiddenLoading()";
  1134. methodJS =@"hiddenLoading";
  1135. }else{
  1136. textJS = [NSString stringWithFormat:@"uploadImg('%@')",url];
  1137. methodJS = @"uploadImg";
  1138. }
  1139. if ([url isEqualToString:@""]||[textJS isEqualToString:@""]) {
  1140. NSLog(@"空的情况");
  1141. textJS = @"hiddenLoading()";
  1142. methodJS = @"hiddenLoading";
  1143. }
  1144. NSDictionary *dict = @{@"jsStr":textJS,@"name":methodJS};
  1145. [self performSelector:@selector(uploadJS:) withObject:dict afterDelay:1];
  1146. }
  1147. //获取到图片
  1148. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
  1149. {
  1150. dispatch_async(dispatch_get_main_queue(), ^{
  1151. [picker dismissViewControllerAnimated:YES completion:^{
  1152. UIImage * img=[info objectForKey:UIImagePickerControllerEditedImage];
  1153. NSData *data = UIImageJPEGRepresentation(img, 0.5);
  1154. if (data!=nil) {
  1155. [self uploadPic:data];
  1156. }else{
  1157. NSLog(@"data == nil");
  1158. [self uploadUrl:@""];
  1159. }
  1160. }];
  1161. });
  1162. }
  1163. -(void)uploadJS:(NSDictionary *)dict {
  1164. [self isExitCallToJS:dict[@"jsStr"] withMethodName:dict[@"name"]];
  1165. }
  1166. - (BOOL)checkLocationServiceIsEnabled{
  1167. // 该方法是类方法,和我们创建的管理器没有关系
  1168. if ([CLLocationManager locationServicesEnabled]) {
  1169. return YES;
  1170. }
  1171. return NO;
  1172. }
  1173. -(NSString *)convertToJsonData:(NSDictionary *)dict {
  1174. NSError *error;
  1175. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
  1176. NSString *jsonString;
  1177. if (!jsonData) {
  1178. NSLog(@"%@",error);
  1179. }else{
  1180. jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
  1181. }
  1182. NSMutableString *mutStr = [NSMutableString stringWithString:jsonString];
  1183. NSRange range = {0,jsonString.length};
  1184. //去掉字符串中的空格
  1185. [mutStr replaceOccurrencesOfString:@" " withString:@"" options:NSLiteralSearch range:range];
  1186. NSRange range2 = {0,mutStr.length};
  1187. //去掉字符串中的换行符
  1188. [mutStr replaceOccurrencesOfString:@"\n" withString:@"" options:NSLiteralSearch range:range2];
  1189. return mutStr;
  1190. }
  1191. -(void)addNoNetViews{
  1192. kMainQueue(^{
  1193. self.recognizer.enabled = NO;
  1194. [self removeNoNetViews];
  1195. //about:blank
  1196. self.noNetView = [NoNetView shareView];
  1197. [self.view addSubview:self.noNetView];
  1198. });
  1199. }
  1200. -(void)removeNoNetViews{
  1201. if (self.noNetView ) {
  1202. self.recognizer.enabled = YES;
  1203. [self.noNetView removeFromSuperview];
  1204. self.noNetView = nil;
  1205. }
  1206. }
  1207. -(void)addFailNetViews{
  1208. kMainQueue(^{
  1209. self.recognizer.enabled = NO;
  1210. [self removeFailNetViews];
  1211. self.failNetView = [NoNetView shareView];
  1212. [self.view addSubview:self.failNetView];
  1213. });
  1214. }
  1215. -(void)removeFailNetViews{
  1216. if (self.failNetView ) {
  1217. self.recognizer.enabled = YES;
  1218. [self.failNetView removeFromSuperview];
  1219. self.failNetView = nil;
  1220. }
  1221. }
  1222. #pragma mark **** 通知相关方法
  1223. -(void)openPushUrlMethodsFour:(NSNotification *)notification{
  1224. NSDictionary *infoDict = notification.userInfo;
  1225. if (!infoDict) {return;}
  1226. NSString * urlStr = [NSString stringWithFormat:@"%@",infoDict[@"url"]];
  1227. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]]];
  1228. }
  1229. -(void)openPushLinkUrlMethods:(NSNotification *)notification{
  1230. NSDictionary *infoDict = notification.userInfo;
  1231. if (!infoDict) {return;}
  1232. NSString * urlStr = [NSString stringWithFormat:@"%@",infoDict[@"url"]];
  1233. if (self.tabBarController.selectedIndex == 3) {
  1234. [self JsOpenExternalLink:@{@"url":urlStr,@"title":@"消息通知"}];
  1235. }
  1236. }
  1237. -(void)alipayWXpayStatus:(NSNotification *)notification{
  1238. if(self.tabBarController.selectedIndex == 3) {
  1239. NSString * status = [notification object];
  1240. [self performSelector:@selector(payStatus:) withObject:status afterDelay:2];
  1241. }
  1242. }
  1243. -(void)payStatus:(NSString *)status
  1244. {
  1245. NSLog(@"支付状态:%@",status);//目前延时两秒
  1246. if(self.tabBarController.selectedIndex == 3) {
  1247. [self isExitCallToJS:[NSString stringWithFormat:@"payCallBack('%@')", status] withMethodName:@"payCallBack"];
  1248. }
  1249. }
  1250. // 调用js方法 刷新推送权限状态
  1251. -(void)updateNotifyState:(NSNotification *)notification{
  1252. if (self.updateNotify) {
  1253. self.updateNotify = NO;
  1254. [self isExitCallToJS:[NSString stringWithFormat:@"updateNoticeSwitch()"] withMethodName:@"updateNoticeSwitch"];
  1255. }
  1256. }
  1257. // 再次加载页面
  1258. -(void)reloadWebView:(NSNotification *)notification{
  1259. if(self.tabBarController.selectedIndex == 3) {
  1260. if (![self.webView canGoBack]) {
  1261. [self webViewFirstRequest];
  1262. }else{
  1263. [self.webView reload];
  1264. }
  1265. }
  1266. }
  1267. // 返回上一页面- 防止
  1268. -(void)popWebView:(NSNotification *)notification{
  1269. if(self.tabBarController.selectedIndex == 3) {
  1270. if ([self.webView canGoBack]) {
  1271. [self.webView goBack];
  1272. }
  1273. [self removeNoNetViews];
  1274. [self removeFailNetViews];
  1275. }
  1276. }
  1277. // 收到退出登录消息
  1278. -(void)loginOut:(NSNotification *)notification{
  1279. if([notification.userInfo[@"item_index"] integerValue]!=3) {
  1280. return;
  1281. }
  1282. NSString *url = [NSString stringWithFormat:@"%@%@", kHost, @"jyapp/free/login?back=index&isios=t&flag=kicked"];
  1283. url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  1284. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
  1285. }
  1286. // 监控网络状态变化
  1287. -(void)netReachChanged:(NSNotification *)notificaition{
  1288. NSDictionary *userInfo = notificaition.userInfo;
  1289. if ([userInfo[@"AFNetworkingReachabilityNotificationStatusItem"] intValue] == 0 || [userInfo[@"AFNetworkingReachabilityNotificationStatusItem"] intValue] == -1) {
  1290. [self addNoNetViews];
  1291. }else{
  1292. [self removeNoNetViews];
  1293. if (isExistNoNewWork) {
  1294. isExistNoNewWork = NO;
  1295. [self reloadWebView:nil];
  1296. }
  1297. }
  1298. }
  1299. -(void)jyReceiveNewsRedPoint:(NSNotification *)notificaition {
  1300. NSDictionary *dict = notificaition.userInfo;
  1301. if(self.tabBarController.selectedIndex == 3) {
  1302. NSString *textJS = [NSString stringWithFormat:@"afterReceivePushMessage('%@','%@')",dict[@"typeMsg"],dict[@"url"]];
  1303. [self isExitCallToJS:textJS withMethodName:@"afterReceivePushMessage"];
  1304. }
  1305. }
  1306. //刷新页面相关
  1307. -(void)refreshNonCurVC:(NSNotification *)notificaition{
  1308. if(self.tabBarController.selectedIndex != 3) {
  1309. [self webViewFirstRequest];
  1310. }
  1311. }
  1312. -(void)refreshAllVC:(NSNotification *)notificaition{
  1313. [self webViewFirstRequest];
  1314. }
  1315. -(void)refreshExpAndMine:(NSNotification *)notificaition{
  1316. [self webViewFirstRequest];
  1317. }
  1318. //内购相关
  1319. -(void)receiptData:(NSNotification *)notificaition{
  1320. if(self.tabBarController.selectedIndex == 3) {
  1321. NSDictionary *infoDict = notificaition.userInfo;
  1322. if (infoDict) {
  1323. NSString *receipt = [NSString stringWithFormat:@"%@", infoDict[@"receipt"]];
  1324. [self isExitCallToJS:[NSString stringWithFormat:@"getReceipt('%@')", receipt] withMethodName:@"getReceipt"];
  1325. }
  1326. }
  1327. }
  1328. #pragma mark ****粘贴板相关-梳理
  1329. -(void)updateClipboard:(NSNotification *)notificaition{
  1330. if(self.tabBarController.selectedIndex == 3) {
  1331. NSString *current_url = [self stringByEvaluatingJavaScriptFromString:@"document.location.href"];
  1332. NSDictionary *dict = notificaition.userInfo;
  1333. NSString *content = [NSString stringWithFormat:@"%@",dict[@"content"]];
  1334. if ([current_url containsString:@"jyapp/free/login"]) {
  1335. [GlobalData shareInstance].isPasteLogin = YES;
  1336. }else {
  1337. [self popPasteVIew:content];
  1338. }
  1339. }
  1340. }
  1341. -(void)openTheClipboard:(NSNotification *)notificaition{
  1342. if(self.tabBarController.selectedIndex == 3) {
  1343. NSLog(@"菜单四打开指定粘贴板url");
  1344. NSDictionary *dict = notificaition.userInfo;
  1345. NSString *tmpUrl = [NSString stringWithFormat:@"%@%@", kHost, dict[@"url"]];
  1346. tmpUrl = [tmpUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  1347. kMainQueue(^{
  1348. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:tmpUrl]]];
  1349. })
  1350. }
  1351. }
  1352. //弹出粘贴板框
  1353. -(void)popPasteVIew:(NSString *)content {
  1354. [[LXNetworkManager shareLXNetworkManager]postWithURLStr:[NSString stringWithFormat:@"%@distribution/share/getWordInfo",kHost] parameters:@{@"copyTxt":content} progress:^(NSProgress *progress) {
  1355. NSLog(@"%@",progress);
  1356. } success:^(id responseObject) {
  1357. NSLog(@"responseObject=%@",responseObject);
  1358. if ([responseObject objectForKey:@"data"]) {
  1359. NSDictionary *dict = [[NSDictionary alloc]initWithDictionary:responseObject[@"data"]];
  1360. if ([dict objectForKey:@"title"]) {
  1361. self.clipboardView.title =dict[@"title"];
  1362. self.clipboardView.subTitle =dict[@"subTitle"];
  1363. self.clipboardView.imgUrl =dict[@"imgUrl"];
  1364. self.clipboardView.appUrl =dict[@"appUrl"];
  1365. self.clipboardView.butTxt =dict[@"butTxt"];
  1366. self.clipboardView.bottomTxt =dict[@"bottomTxt"];
  1367. [self.clipboardView show];
  1368. }
  1369. }
  1370. } failure:^(NSError *error) {
  1371. NSLog(@"error=%@",error);
  1372. }];
  1373. }
  1374. #pragma mark **** 代理方法
  1375. -(void)clipboardClick:(NSString *)url {
  1376. //发送通知打开粘贴板-url
  1377. [[NSNotificationCenter defaultCenter] postNotificationName:OpenTheClipboard object:nil userInfo:@{@"url":url}];
  1378. }
  1379. /*
  1380. #pragma mark - Navigation
  1381. // In a storyboard-based application, you will often want to do a little preparation before navigation
  1382. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  1383. // Get the new view controller using [segue destinationViewController].
  1384. // Pass the selected object to the new view controller.
  1385. }
  1386. */
  1387. @end