JYNewSearchViewController.m 60 KB

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