JYBaseViewController.m 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893
  1. //
  2. // JYBaseViewController.m
  3. // JianYuIOS
  4. //
  5. // Created by 郑坤 on 2023/8/14.
  6. // Copyright © 2023 lixianglan. All rights reserved.
  7. //
  8. #import "JYBaseViewController.h"
  9. #import <WebKit/WebKit.h>
  10. #import <CoreLocation/CoreLocation.h>
  11. #import <GRPCClient/GRPCCall+ChannelArg.h>
  12. #import <GRPCClient/GRPCCall+Tests.h>
  13. #import "MBProgressHUD.h"
  14. @interface JYBaseViewController ()<WKNavigationDelegate,WKUIDelegate,WKScriptMessageHandler,CLLocationManagerDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate,CLLocationManagerDelegate,SKProductsRequestDelegate,SKPaymentTransactionObserver,ZKClipboardViewDelegate,UIDocumentPickerDelegate>
  15. {
  16. CGPoint startTouch;
  17. BOOL _isMoving;
  18. BOOL isExistNoNewWork;
  19. }
  20. @property (nonatomic, strong) UIProgressView *progressView;
  21. @property (nonatomic, strong) WKWebView *webView;
  22. @property(nonatomic,strong)CLLocationManager *locaationManager;
  23. @property(nonatomic,strong)NSString *placeAdr;
  24. @property(nonatomic,strong)NSString *placeLli;
  25. @property(nonatomic,assign)BOOL isLocation;
  26. @property(nonatomic,assign)BOOL isCanBack;
  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. //进度条是否加载中
  33. @property(nonatomic, assign)BOOL isRuningLoad;
  34. @end
  35. NSString *const new_kInitVector = @"1389461544135476";
  36. size_t const new_kKeySize = kCCKeySizeAES128;
  37. NSString *const new_AesKey = @"mGlAgnIBB8bx2nch";
  38. @implementation JYBaseViewController
  39. -(void)viewWillAppear:(BOOL)animated
  40. {
  41. [super viewWillAppear:animated];
  42. [self.navigationController setNavigationBarHidden:YES animated:animated];
  43. if ([GlobalData shareInstance].isClickNotiStatus) {
  44. [GlobalData shareInstance].searchIsRed = NO;
  45. [GlobalData shareInstance].isClickNotiStatus = NO;
  46. }else {
  47. if([GlobalData shareInstance].searchIsRed) {
  48. [GlobalData shareInstance].searchIsRed = NO;
  49. [self webViewFirstRequest];
  50. }
  51. }
  52. }
  53. //弹框
  54. -(ZKFaceVerifyMsgView *)verifyMsgView
  55. {
  56. if(!_verifyMsgView) {
  57. _verifyMsgView = [[ZKFaceVerifyMsgView alloc]initWithFrame:CGRectMake(0, 0, WIDTH*0.8, 150)];
  58. _verifyMsgView.titleName = @"温馨提示";
  59. }
  60. return _verifyMsgView;
  61. }
  62. //弹框
  63. -(ZKClipboardView *)clipboardView{
  64. if(!_clipboardView) {
  65. _clipboardView = [[ZKClipboardView alloc]initWithFrame:CGRectMake(0, 0, WIDTH*0.8, 180+90)];
  66. _clipboardView.delegate = self;
  67. }
  68. return _clipboardView;
  69. }
  70. //进 条
  71. - (UIProgressView *)progressView
  72. {
  73. if (_progressView == nil) {
  74. _progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(0,STATUS_BAR_HEIGHT - 2,WIDTH,2)];
  75. _progressView.tintColor = [UIColor blueColor];
  76. _progressView.trackTintColor = [UIColor whiteColor];
  77. }
  78. return _progressView;
  79. }
  80. //懒加载
  81. - (WKWebView *)webView
  82. {
  83. if(_webView == nil) {
  84. WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
  85. config.preferences = [[WKPreferences alloc] init];
  86. config.preferences.minimumFontSize = 0;
  87. config.allowsInlineMediaPlayback = YES;
  88. config.preferences.javaScriptEnabled = YES;
  89. config.preferences.javaScriptCanOpenWindowsAutomatically = YES;
  90. //添加消息处理,注意:self指代的是需要遵守WKScriptMessageHandler协议,结束时需要移除
  91. NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
  92. config.applicationNameForUserAgent = [NSString stringWithFormat:@" jianyuapp %@",version];
  93. config.userContentController = [[WKUserContentController alloc] init];
  94. //声明协议
  95. NSArray *jsArr = @[@"loginByWeixin",
  96. @"share",
  97. @"saveUserToken",
  98. @"removeUserToken",
  99. @"openSystemNotification",
  100. @"openExternalLink",
  101. @"alert",
  102. @"hiddenBottom",
  103. @"checkLab",
  104. @"loginSuccess",
  105. @"backUrl",
  106. @"clearPushMessage",
  107. @"hideRedSpotOnMenu",
  108. @"showRedSpotOnMenu",
  109. @"wxPay",
  110. @"aliPay",
  111. @"chooseTab",
  112. @"skipCameraWithParam",
  113. @"skipAlbumWithParam",
  114. @"openActivityPage",
  115. @"callPhone",
  116. @"openOtherAppLinks",
  117. @"inPurchasingVip",
  118. @"wirteRight",
  119. @"clearRight",
  120. @"savePic",
  121. @"skipAppointTab",
  122. @"refreshAppointTab",
  123. @"sendMsgCount",
  124. @"downLoadFile",
  125. @"clearHistory",
  126. @"sideslipOpen",
  127. @"sideslipClose",
  128. @"getLogin",
  129. @"checkLoginEnvAvailable",
  130. @"getPhoneBind"
  131. ];
  132. for (NSString*jsName in jsArr) {
  133. [config.userContentController addScriptMessageHandler:self name:jsName];
  134. }
  135. //高端的自定义配置创建WKWebView
  136. if (iPhoneX) {
  137. _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) configuration:config];
  138. if (@available(iOS 11.0, *)) {
  139. _webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  140. }
  141. }else {
  142. _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, -STATUS_BAR_HEIGHT, WIDTH, HEIGHT+STATUS_BAR_HEIGHT) configuration:config];
  143. }
  144. _webView.scrollView.bounces = NO;
  145. _webView.UIDelegate = self;
  146. _webView.navigationDelegate = self;
  147. _webView.userInteractionEnabled = YES;
  148. [_webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
  149. }
  150. return _webView;
  151. }
  152. -(void)webViewFirstRequest{
  153. NSString *tmpUrl = [[NSString stringWithFormat:@"%@jyapp/free/index?sign=%@&deviceid=%@", kHost,[LXUserDefaults token],[LXUserDefaults getDeviceID]] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  154. kMainQueue(^{
  155. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:tmpUrl]]];
  156. })
  157. }
  158. #pragma mark - event response
  159. // 计算wkWebView进度条
  160. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
  161. // NSLog(@"进度条加载中...");
  162. if (!self.isRuningLoad) {
  163. self.isRuningLoad = YES;
  164. }
  165. if (object == self.webView && [keyPath isEqualToString:@"estimatedProgress"]) {
  166. CGFloat newprogress = [[change objectForKey:NSKeyValueChangeNewKey] doubleValue];
  167. self.progressView.alpha = 1.0f;
  168. [self.progressView setProgress:newprogress animated:YES];
  169. if (newprogress >= 1.0f) {
  170. NSLog(@"进度条加载完毕...");
  171. self.isRuningLoad = NO;
  172. self.recognizer.enabled = YES;
  173. [UIView animateWithDuration:0.3f
  174. delay:0.3f
  175. options:UIViewAnimationOptionCurveEaseOut
  176. animations:^{
  177. self.progressView.alpha = 0.0f;
  178. }
  179. completion:^(BOOL finished) {
  180. [self.progressView setProgress:0 animated:NO];
  181. }];
  182. }
  183. } else {
  184. [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
  185. }
  186. }
  187. -(void)initNotification {
  188. //加载通知
  189. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(openPushUrlOtherMethods:) name:OpenPushUrlOtherMethods object:nil];
  190. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(openPushLinkUrlMethods:) name:OpenPushLinkUrlMethods object:nil];
  191. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jyReceiveNewsRedPoint:) name:JYReceiveNewsRedPoint object:nil];
  192. //支付状态通知
  193. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(alipayWXpayStatus:) name:AlipayWXpayStatus object:nil];
  194. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notNetReloadWebVIew:) name:NotNetReloadWebVIew object:nil];
  195. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(popWebView:) name:PopWebView object:nil];
  196. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginOut:) name:kLoginOut object:nil];
  197. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netReachChanged:) name:AFNetworkingReachabilityDidChangeNotification object:nil];
  198. //前往登录通知
  199. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(isLoginTabBar:) name:LoginIndexTabBar object:nil];
  200. //展示底部红的通知
  201. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jyReceiveNewsRedPoint:) name:JYReceiveNewsRedPoint object:nil];
  202. //粘贴板-
  203. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateClipboard:) name:UpdateClipboard object:nil];
  204. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(openTheClipboard:) name:OpenTheClipboard object:nil];
  205. }
  206. #pragma mark – Gesture Recognizer –
  207. -(void)paningGestureReceive:(UIPanGestureRecognizer *)recoginzer{
  208. if (!self.isCanBack){
  209. NSLog(@"不可返回...");
  210. return;
  211. }
  212. NSString *current_url = [self stringByEvaluatingJavaScriptFromString:@"document.location.href"];
  213. NSLog(@"%@",current_url);
  214. CGRect rect = self.view.bounds;
  215. CGFloat width = CGRectGetWidth(rect);
  216. if (![self.webView canGoBack] || ([current_url containsString:@"jyapp/free/login"])) {
  217. NSLog(@"不可返回");
  218. return;
  219. }
  220. if([current_url isEqualToString:[NSString stringWithFormat:@"%@jyapp/free/me",kHost]]||
  221. [current_url isEqualToString:[NSString stringWithFormat:@"%@jyapp/jylab/index",kHost]]||
  222. [current_url isEqualToString:[NSString stringWithFormat:@"%@jyapp/swordfish/historypush",kHost]]||
  223. [current_url isEqualToString:[NSString stringWithFormat:@"%@jyapp/jylab/mainSearch",kHost]]||
  224. [current_url isEqualToString:[NSString stringWithFormat:@"%@jyapp/frontPage/messageCenter/sess/index",kHost]]){
  225. return;
  226. }
  227. CGPoint touchPoint = [recoginzer locationInView:[UIApplication sharedApplication].keyWindow];
  228. if (recoginzer.state==UIGestureRecognizerStateBegan) {
  229. _isMoving = YES;
  230. startTouch = touchPoint;
  231. } else if (recoginzer.state==UIGestureRecognizerStateEnded||(recoginzer.state==UIGestureRecognizerStatePossible)){
  232. if (touchPoint.x - startTouch.x > width*0.125) {
  233. [UIView animateWithDuration:0.3 animations:^{
  234. if (recoginzer.state==UIGestureRecognizerStateEnded) {
  235. [self moveViewWithX:width];
  236. if ([current_url containsString:@"jyapp/jylab/mainSearch#"]) {
  237. [self isExitCallToJS:@"afterClickBack()" withMethodName:@"afterClickBack"];
  238. }
  239. [self.webView goBack];
  240. }
  241. } completion:^(BOOL finished) {
  242. self->_isMoving = NO;
  243. [self moveViewWithX:0];
  244. }];
  245. } else {
  246. [UIView animateWithDuration:0.3 animations:^{
  247. [self moveViewWithX:0];
  248. } completion:^(BOOL finished) {
  249. self->_isMoving = NO;
  250. }];
  251. }
  252. return;
  253. } else if (recoginzer.state==UIGestureRecognizerStateCancelled){
  254. [UIView animateWithDuration:0.3 animations:^{
  255. [self moveViewWithX:0];
  256. } completion:^(BOOL finished) {
  257. self->_isMoving = NO;
  258. }];
  259. return;
  260. }else {
  261. }
  262. if (_isMoving) {
  263. [self moveViewWithX:touchPoint.x - startTouch.x];
  264. }
  265. }
  266. -(void)moveViewWithX:(float)x
  267. {
  268. CGRect rect = self.view.bounds;
  269. CGFloat width = CGRectGetWidth(rect);
  270. x = x>width?width:x;
  271. x = x<0?0:x;
  272. CGRect frame = self.webView.frame;
  273. frame.origin.x = x;
  274. self.webView.frame = frame;
  275. }
  276. - (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message{
  277. // message.body -- Allowed types are NSNumber, NSString, NSDate, NSArray,NSDictionary, and NSNull.
  278. NSLog(@"原生收到了js发送过来的消息message.name = %@ message.body = %@",message.name,message.body);
  279. if ([message.name isEqualToString:@"loginByWeixin"]) {
  280. [self jsLoginByWeixin:message.body];
  281. }else if ([message.name isEqualToString:@"share"]) {
  282. [self jsShare:message.body];
  283. }else if ([message.name isEqualToString:@"saveUserToken"]) {
  284. [self jsSaveUserToken:message.body];
  285. }else if ([message.name isEqualToString:@"removeUserToken"]) {
  286. [self jsRemoveUserToken:message.body];
  287. }else if ([message.name isEqualToString:@"openSystemNotification"]) {
  288. [self jsOpenSystemNotification:message.body];
  289. }else if ([message.name isEqualToString:@"openExternalLink"]) {
  290. [self JsOpenExternalLink:message.body];
  291. }else if ([message.name isEqualToString:@"alert"]) {
  292. [self jsAlert:message.body];
  293. }else if ([message.name isEqualToString:@"hiddenBottom"]) {
  294. // [self jsHiddenBottom:message.body];
  295. }else if ([message.name isEqualToString:@"checkLab"]) {
  296. // [self jsCheckLab:message.body];
  297. }else if ([message.name isEqualToString:@"chooseTab"]) {
  298. // [self jsChooseTab:message.body];
  299. }else if ([message.name isEqualToString:@"loginSuccess"]) {
  300. [self jsLoginSuccess:message.body];
  301. }else if ([message.name isEqualToString:@"backUrl"]) {
  302. [self jsBackUrl:message.body];
  303. }else if ([message.name isEqualToString:@"clearPushMessage"]) {
  304. [self jsClearPushMessage:message.body];
  305. }else if ([message.name isEqualToString:@"hideRedSpotOnMenu"]) {
  306. // [self jsHideRedSpotOnMenu:message.body];
  307. }else if ([message.name isEqualToString:@"showRedSpotOnMenu"]) {
  308. // [self jsShowRedSpotOnMenu:message.body];
  309. }else if ([message.name isEqualToString:@"wxPay"]) {
  310. [self jsWxPay:message.body];
  311. }else if ([message.name isEqualToString:@"aliPay"]) {
  312. [self jsAliPay:message.body];
  313. }else if ([message.name isEqualToString:@"skipCameraWithParam"]) {
  314. [self jsSkipCameraWithParam:message.body];
  315. }else if ([message.name isEqualToString:@"skipAlbumWithParam"]) {
  316. [self jsSkipAlbumWithParam:message.body];
  317. }else if ([message.name isEqualToString:@"openActivityPage"]) {
  318. [self jsOpenActivityPage:message.body];
  319. }else if ([message.name isEqualToString:@"callPhone"]) {
  320. [self jsCallPhone:message.body];
  321. }else if ([message.name isEqualToString:@"openOtherAppLinks"]) {
  322. [self jsOpenOtherAppLinks:message.body];
  323. }else if ([message.name isEqualToString:@"inPurchasingVip"]) {
  324. [self jsInPurchasingVip:message.body];
  325. }else if ([message.name isEqualToString:@"wirteRight"]) {
  326. [self jsWirteRight:message.body];
  327. }else if ([message.name isEqualToString:@"clearRight"]) {
  328. [self jsClearRight:message.body];
  329. }else if ([message.name isEqualToString:@"savePic"]) {
  330. [self jsSavePic:message.body];
  331. }else if ([message.name isEqualToString:@"skipAppointTab"]) {
  332. // [self jsSkipAppointTab:message.body];
  333. }else if ([message.name isEqualToString:@"refreshAppointTab"]) {
  334. // [self jsRefreshAppointTab:message.body];
  335. }else if ([message.name isEqualToString:@"sendMsgCount"]) {
  336. // [self jsSendMsgCount:message.body];
  337. }else if ([message.name isEqualToString:@"downLoadFile"]) {
  338. [self jsDownLoadFile:message.body];
  339. }else if ([message.name isEqualToString:@"clearHistory"]) {
  340. [self jsClearHistory:message.body];
  341. }else if ([message.name isEqualToString:@"sideslipOpen"]) {
  342. [self jsSideslipOpen:message.body];
  343. }else if ([message.name isEqualToString:@"sideslipClose"]) {
  344. [self jsSideslipClose:message.body];
  345. }else if ([message.name isEqualToString:@"getLogin"]) {
  346. [self jsGetLogin:message.body];
  347. }else if ([message.name isEqualToString:@"checkLoginEnvAvailable"]) {
  348. [self jsCheckLoginEnvAvailable:message.body];
  349. }else if ([message.name isEqualToString:@"getPhoneBind"]) {
  350. [self jsGetPhoneBind:message.body];
  351. }else {
  352. }
  353. }
  354. #pragma mark - WKUIDelegate
  355. - (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(nullable NSString *)defaultText initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSString * _Nullable result))completionHandler
  356. {
  357. NSError *err = nil;
  358. NSData *dataFromString = [prompt dataUsingEncoding:NSUTF8StringEncoding];
  359. NSDictionary *paramdict = [NSJSONSerialization JSONObjectWithData:dataFromString options:NSJSONReadingMutableContainers error:&err];
  360. // NSLog(@"拦截prompt:%@",paramdict);
  361. if (!err){
  362. NSString *type = [paramdict objectForKey:@"jsName"];
  363. if (type && [type isEqualToString:@"getUserToken"]) {
  364. NSDictionary *dict = @{@"type":@"string",
  365. @"value":[self jsGetUserToken:paramdict]};
  366. completionHandler([self convertToJsonData:dict]);
  367. }else if (type && [type isEqualToString:@"getVersion"]) {
  368. NSDictionary *dict = @{@"type":@"string",
  369. @"value":[self jsGetVersion:paramdict]};
  370. completionHandler([self convertToJsonData:dict]);
  371. }else if (type && [type isEqualToString:@"checkNoticePermission"]) {
  372. NSDictionary *dict = @{@"type":@"int",
  373. @"value":[NSString stringWithFormat:@"%d",[self jsCheckNoticePermission:paramdict]]};
  374. completionHandler([self convertToJsonData:dict]);
  375. }else if (type && [type isEqualToString:@"getPushRid"]) {
  376. NSDictionary *dict = @{@"type":@"string",@"value":[self jsGetPushRid:paramdict]};
  377. completionHandler([self convertToJsonData:dict]);
  378. }else if (type && [type isEqualToString:@"isInstallWeixin"]) {
  379. NSDictionary *dict = @{@"type":@"int",
  380. @"value":[NSString stringWithFormat:@"%d",[self jsIsInstallWeixin:paramdict]]};
  381. completionHandler([self convertToJsonData:dict]);
  382. }else if (type && [type isEqualToString:@"getCipherText"]) {
  383. NSDictionary *dict = @{@"type":@"string",
  384. @"value":[self jsGetCipherText:paramdict]};
  385. completionHandler([self convertToJsonData:dict]);
  386. }
  387. else if (type && [type isEqualToString:@"getOtherPushRid"]) {
  388. NSDictionary *dict = @{@"type":@"string",@"value":[self jsGetOtherPushRid:paramdict]};
  389. completionHandler([self convertToJsonData:dict]);
  390. }else if (type && [type isEqualToString:@"getPhoneBrand"]) {
  391. NSDictionary *dict = @{@"type":@"string",
  392. @"value":[self jsGetPhoneBrand:paramdict]};
  393. completionHandler([self convertToJsonData:dict]);
  394. }else if (type && [type isEqualToString:@"getLocation"]) {
  395. NSDictionary *dict = @{@"type":@"string",
  396. @"value":[self jsGetLocation:paramdict]};
  397. completionHandler([self convertToJsonData:dict]);
  398. }else if (type && [type isEqualToString:@"getLLitude"]) {
  399. NSDictionary *dict = @{@"type":@"string",
  400. @"value":[self jsGetLLitude:paramdict]};
  401. completionHandler([self convertToJsonData:dict]);
  402. }else if (type && [type isEqualToString:@"readRight"]) {
  403. NSDictionary *dict = @{@"type":@"string",
  404. @"value":[self jsReadRight:paramdict]};
  405. completionHandler([self convertToJsonData:dict]);
  406. }else if (type && [type isEqualToString:@"checkLocationPermission"]) {
  407. NSDictionary *dict = @{@"type":@"int",
  408. @"value":[NSString stringWithFormat:@"%d",[self jsCheckLocationPermission:paramdict]]
  409. };
  410. completionHandler([self convertToJsonData:dict]);
  411. }else {
  412. completionHandler(@"");
  413. }
  414. }
  415. }
  416. -(WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures{
  417. //假如是重新打开窗口的话
  418. if (!navigationAction.targetFrame.isMainFrame) {
  419. [webView loadRequest:navigationAction.request];
  420. }
  421. return nil;
  422. }
  423. // 在发送请求之前,决定是否跳转
  424. - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
  425. //如果当前页面是三级页面-
  426. NSString *curUrl = [webView.URL absoluteString];
  427. if (navigationAction.targetFrame==nil) {
  428. [webView loadRequest:navigationAction.request];
  429. }
  430. if ([curUrl containsString:@"jyapp/article/content"]) {
  431. //当前页面是三级页面--判断待跳转页面是否符合内置跳转
  432. NSString *nextUrl = [navigationAction.request.URL absoluteString];
  433. if ([nextUrl containsString:@"jianyu360.com"]||
  434. [nextUrl containsString:@"jianyu360.cn"]||
  435. [nextUrl containsString:@"qmx.top"]) {//允许跳转
  436. decisionHandler(WKNavigationActionPolicyAllow);
  437. }else {
  438. NSLog(@"不允许内部跳转:-%@",nextUrl);
  439. //筛选拦截-压缩包等格式不允许跳转
  440. if ([nextUrl hasSuffix:@".rar"]||
  441. [nextUrl hasSuffix:@".zip"]||
  442. [nextUrl hasSuffix:@".7z"]||
  443. [nextUrl hasSuffix:@".CAB"]||
  444. [nextUrl hasSuffix:@".ARJ"]||
  445. [nextUrl hasSuffix:@".LZH"]||
  446. [nextUrl hasSuffix:@".TAR"]||
  447. [nextUrl hasSuffix:@".GZ"]||
  448. [nextUrl hasSuffix:@".ACE"]||
  449. [nextUrl hasSuffix:@".UUE"]||
  450. [nextUrl hasSuffix:@".BZ2"]||
  451. [nextUrl hasSuffix:@".JAR"]||
  452. [nextUrl hasSuffix:@".ISO"]) {
  453. // 不允许跳转
  454. decisionHandler(WKNavigationActionPolicyCancel);
  455. }else {
  456. JYWKNewWebController *ctr = [[JYWKNewWebController alloc] init];
  457. ctr.url = nextUrl;
  458. ctr.titleShow = @"公告信息";
  459. kMainQueue(^{
  460. [self presentViewController:ctr animated:YES completion:nil];
  461. });
  462. // 不允许跳转-并跳转新页面
  463. decisionHandler(WKNavigationActionPolicyCancel);
  464. }
  465. }
  466. }else if ([curUrl containsString:@"apps.apple.com"]&&[curUrl containsString:@"1354897149"]){
  467. [[UIApplication sharedApplication] openURL:[NSURL URLWithString: curUrl]];
  468. decisionHandler(WKNavigationActionPolicyCancel);
  469. }else {
  470. // 允许跳转
  471. decisionHandler(WKNavigationActionPolicyAllow);
  472. }
  473. }
  474. #pragma mark ****WKUIDelegate
  475. //通过js alert 显示一个警告面板,调用原生会走此方法。
  476. - (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler
  477. {
  478. // NSLog(@"显示一个JavaScript警告面板, message = %@",message);
  479. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:message preferredStyle:UIAlertControllerStyleAlert];
  480. [alertController addAction:[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  481. completionHandler();
  482. }]];
  483. [self presentViewController:alertController animated:YES completion:nil];
  484. }
  485. //通过 js confirm 显示一个确认面板,调用原生会走此方法。
  486. - (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL result))completionHandler
  487. {
  488. // NSLog(@"运行JavaScript确认面板, message = %@", message);
  489. UIAlertController *action = [UIAlertController alertControllerWithTitle:@"温馨提示" message:message preferredStyle:UIAlertControllerStyleAlert];
  490. [action addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  491. completionHandler(NO);
  492. }] ];
  493. [action addAction:[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  494. completionHandler(YES);
  495. }]];
  496. [self presentViewController:action animated:YES completion:nil];
  497. }
  498. #pragma mark - OC调JS交互
  499. -(void)isExitCallToJS:(NSString *)jsStr withMethodName:(NSString *)name{
  500. NSString *jsName = [NSString stringWithFormat:@"function exist(){return !window['%@']};exist()",name];
  501. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.15 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  502. WeakSelf;
  503. [self->_webView evaluateJavaScript:jsName completionHandler:^(id _Nullable result, NSError * _Nullable error) {
  504. // NSLog(@"是否存在 result:%@,error:%@",result,error);
  505. if ([result intValue]==0) {
  506. [weakSelf executeCallJS:jsStr];
  507. }else {
  508. NSLog(@"不存在-不存在-不存在-%@",jsStr);
  509. }
  510. }];
  511. });
  512. }
  513. -(void)executeCallJS:(NSString *)jsStr {
  514. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.15 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  515. [self->_webView evaluateJavaScript:jsStr completionHandler:^(id _Nullable result, NSError * _Nullable error) {
  516. if (error!=nil) {
  517. }
  518. }];
  519. });
  520. }
  521. - (void)viewDidLoad {
  522. [super viewDidLoad];
  523. // Do any additional setup after loading the view.
  524. NSLog(@"首页初始化");
  525. self.placeAdr = [NSString new];
  526. self.placeLli = [NSString new];
  527. self.isCanBack = YES;
  528. self.view.backgroundColor = [UIColor whiteColor];
  529. [self.view addSubview:self.webView];
  530. [self.view addSubview:self.progressView];
  531. [self webViewFirstRequest];
  532. [[AFNetworkReachabilityManager sharedManager] startMonitoring];
  533. [self initNotification];
  534. self.recognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(paningGestureReceive:)];
  535. [self.recognizer delaysTouchesBegan];
  536. [self.view addGestureRecognizer:self.recognizer];
  537. //监听购买结果
  538. [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
  539. // UIButton *btn = [ZKControl createButtonWithFrame:CGRectMake(100, 100, 100, 100) title:@"点我点我" imageName:nil bgImageName:nil target:self method:@selector(click)];
  540. // [self.view addSubview:btn];
  541. }
  542. //-(void)click{
  543. // [self jsGetPhoneBind:@{}];
  544. //}
  545. #pragma mark - WKNavigationDelegate
  546. /* 页面加载完成 */
  547. - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
  548. NSLog(@"-----页面加载完成%@",webView.URL.absoluteString);
  549. //第一次加载小红点
  550. [self.webView evaluateJavaScript:@"document.documentElement.style.webkitTouchCallout='none';" completionHandler:nil];
  551. [self.webView evaluateJavaScript:@"document.documentElement.style.webkitUserSelect='none';"completionHandler:nil];
  552. [self removeNoNetViews];
  553. [self removeFailNetViews];
  554. [[LXViewControllerManager shareViewControllerManager] hideHud];
  555. //写数据
  556. if (![GlobalData shareInstance].isOpen) {//第一次打开
  557. [GlobalData shareInstance].isOpen = YES;
  558. [self performSelector:@selector(pasteboard) withObject:nil afterDelay:1.5];
  559. }
  560. }
  561. -(void)pasteboard {
  562. NSString *content = [UIPasteboard generalPasteboard].string;
  563. if ([content containsString:@"剑鱼标讯"]) {//第一次打开页面时候
  564. [[NSNotificationCenter defaultCenter] postNotificationName:UpdateClipboard object:nil userInfo:@{@"content":content}];
  565. }
  566. }
  567. -(void)writeWKWebData:(NSURL *)url {
  568. //得到NSData 数据
  569. NSData *dataContent = [NSData dataWithContentsOfURL:url];
  570. //NSURLCache 实例化
  571. NSURLCache *cache = [NSURLCache sharedURLCache];
  572. //得到相应
  573. NSURLResponse *response = [[NSURLResponse alloc]initWithURL:url MIMEType:nil expectedContentLength:0 textEncodingName:@"UTF-8"];
  574. //得到CacheURLResponse
  575. NSCachedURLResponse *cacheResponse = [[NSCachedURLResponse alloc]initWithResponse:response data:dataContent];
  576. //进行存储
  577. [cache storeCachedResponse:cacheResponse forRequest:[NSURLRequest requestWithURL:url]];
  578. }
  579. // 页面开始加载时调用
  580. - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{
  581. self.recognizer.enabled = NO;
  582. }
  583. // 当内容开始返回时调用
  584. - (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation{
  585. }
  586. // 页面加载失败时调用
  587. - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(nonnull NSError *)error{
  588. //加载失败 有网络-弹出页面 , 无网络-记录标记
  589. if ([ZKMethod judegeNetworkIsAvailable]) {
  590. //弹出页面
  591. NSLog(@"页面加载失败-有网络");
  592. if (!self.isRuningLoad) {
  593. [self addFailNetViews];
  594. }
  595. }else {
  596. //记录标记
  597. NSLog(@"页面加载失败-无网络");
  598. isExistNoNewWork = YES;
  599. }
  600. self.recognizer.enabled = YES;
  601. }
  602. #pragma mark *****JS与OC交互
  603. #pragma mark - WKScriptMessageHandler JS调OC交互
  604. -(void)jsLoginByWeixin:(NSDictionary *)dict {
  605. if ([LXUserDefaults isInstallWeiXin] != 1) { // 没有安装微信 不走友盟
  606. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"微信登录失败,没有安装微信" delay:1.5];
  607. return;
  608. }
  609. [[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_WechatSession currentViewController:self completion:^(id result, NSError *error) {
  610. UMSocialUserInfoResponse *resp = result;
  611. [self dealWXDic:(NSDictionary *)resp.originalResponse];
  612. }];
  613. }
  614. // 处理微信登录获取到的数据
  615. -(void)dealWXDic:(NSDictionary *)dictionary{
  616. //如果获取到用户信息,即用户点击了“登录”,则进行用户信息获取
  617. if (dictionary.count > 0) {
  618. NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:dictionary];
  619. if (dic) {
  620. [dic removeObjectForKey:@"privilege"];
  621. [dic removeObjectForKey:@"language"];
  622. double currDouble = [[NSDate date] timeIntervalSince1970];
  623. [dic setObject:[NSNumber numberWithLong:(long)currDouble] forKey:@"createtime"];
  624. // 拼接标志位
  625. 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"]];
  626. sign = [LXMD5 md532BitLower:sign];
  627. [dic setObject:sign forKey:@"sign"];
  628. NSString *endStr = [[LXViewControllerManager shareViewControllerManager] getJsonStr:dic];
  629. NSData *data = [endStr dataUsingEncoding:NSUTF8StringEncoding];
  630. endStr = [data base64EncodedStringWithOptions:0];
  631. [self isExitCallToJS:[NSString stringWithFormat:@"loginByWeixinCallBack('%@')", endStr] withMethodName:@"loginByWeixinCallBack"];
  632. }
  633. }
  634. }
  635. -(void)jsShare:(NSDictionary *)dict {
  636. NSString *type = [NSString stringWithFormat:@"%@",dict[@"type"]];
  637. NSString *title = [NSString stringWithFormat:@"%@",dict[@"title"]];
  638. NSString *content = [NSString stringWithFormat:@"%@",dict[@"content"]];
  639. NSString *link = [NSString stringWithFormat:@"%@",dict[@"link"]];
  640. UMSocialPlatformType shareType;
  641. if ([type intValue] == 1) { // 微信好友
  642. shareType = UMSocialPlatformType_WechatSession;
  643. }else if ([type intValue] == 2){ /// qq好友
  644. shareType = UMSocialPlatformType_QQ;
  645. }else if ([type intValue] == 3){ // 朋友圈
  646. shareType = UMSocialPlatformType_WechatTimeLine;
  647. }else{
  648. shareType = UMSocialPlatformType_WechatSession;
  649. }
  650. if ([type intValue] == 1 || [type intValue] == 3) {
  651. if ([LXUserDefaults isInstallWeiXin] != 1) {
  652. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"没有安装微信" delay:1.5];
  653. return;
  654. }
  655. }
  656. if ([type intValue] == 2) {
  657. if (![[UMSocialManager defaultManager] isInstall:UMSocialPlatformType_QQ]) {
  658. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"没有安装QQ" delay:1.5];
  659. return;
  660. }
  661. }
  662. //创建分享消息对象
  663. UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
  664. //创建网页内容对象
  665. UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:title descr:content thumImage:[UIImage imageNamed:@"logo"]];
  666. //设置网页地址
  667. shareObject.webpageUrl = link;
  668. messageObject.shareObject = shareObject;
  669. //调用分享接口
  670. [[UMSocialManager defaultManager] shareToPlatform:shareType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
  671. if (error) {
  672. if (error.userInfo[@"message"] && [error.userInfo[@"message"] containsString:@"Operation is cancel"]) {
  673. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"取消分享" delay:1];
  674. }else{
  675. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:error.userInfo[@"message"] delay:1];
  676. }
  677. [self isExitCallToJS:[NSString stringWithFormat:@"shareCallBack('%@','%@')",type,@"0"] withMethodName:@"shareCallBack"];
  678. }else{
  679. if ([data isKindOfClass:[UMSocialShareResponse class]]) {
  680. [self isExitCallToJS:[NSString stringWithFormat:@"shareCallBack('%@','%@')",type,@"1"] withMethodName:@"shareCallBack"];
  681. }else{
  682. UMSocialLogInfo(@"response data is %@",data);
  683. }
  684. }
  685. }];
  686. }
  687. -(void)jsSaveUserToken:(NSDictionary *)dict{
  688. [LXUserDefaults saveToken:[NSString stringWithFormat:@"%@",dict[@"token"]]];
  689. }
  690. -(NSString *)jsGetUserToken:(NSDictionary *)dict{
  691. return [LXUserDefaults token];
  692. }
  693. -(void)jsRemoveUserToken:(NSDictionary *)dict{
  694. [LXUserDefaults clearAll];
  695. }
  696. -(int)jsCheckNoticePermission:(NSDictionary *)dict{
  697. if ([[UIApplication sharedApplication] currentUserNotificationSettings].types != UIUserNotificationTypeNone) {
  698. return 1;
  699. }
  700. return 0;
  701. }
  702. // 跳转到系统设置
  703. -(void)jsOpenSystemNotification:(NSDictionary *)dict{
  704. [[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
  705. }
  706. // 获取推送id
  707. -(NSString *)jsGetPushRid:(NSDictionary *)dict{
  708. return [LXUserDefaults grpcPushID];
  709. }
  710. // 打开新页面 加载新web
  711. -(void)JsOpenExternalLink:(NSDictionary *)dict{
  712. NSString *url = [NSString stringWithFormat:@"%@",dict[@"url"]];
  713. NSString *title = [NSString stringWithFormat:@"%@",dict[@"title"]];
  714. if (url) {
  715. if ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable || [AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusUnknown) {
  716. }
  717. JYWKNewWebController *ctr = [[JYWKNewWebController alloc] init];
  718. ctr.url = url;
  719. if (!title || [title isEqualToString:@""] || [title isEqualToString:@"undefined"]) {
  720. ctr.titleShow = nil;
  721. }else{
  722. ctr.titleShow = title;
  723. }
  724. kMainQueue(^{
  725. [self presentViewController:ctr animated:YES completion:nil];
  726. });
  727. }
  728. }
  729. // 获取当前版本号
  730. -(NSString *)jsGetVersion:(NSDictionary *)dict{
  731. return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
  732. }
  733. -(void)jsAlert:(NSDictionary *)dict{
  734. [[LXViewControllerManager shareViewControllerManager] showAlertViewWithMessage:[NSString stringWithFormat:@"%@",dict[@"content"]]];
  735. }
  736. -(int)jsIsInstallWeixin:(NSDictionary *)dict{
  737. return [LXUserDefaults isInstallWeiXin];
  738. }
  739. -(NSString *)jsGetCipherText:(NSDictionary *)dict{
  740. NSDictionary *objDict = [NSDictionary dictionaryWithDictionary:dict[@"arguments"]];
  741. NSString *phone = [NSString stringWithFormat:@"%@",objDict[@"phone"]];
  742. NSDate *date=[NSDate date];
  743. NSDateFormatter *format1=[[NSDateFormatter alloc] init];
  744. [format1 setDateFormat:@"yyyyMMddhhmmss"];
  745. NSString *dateStr;
  746. dateStr=[format1 stringFromDate:date];
  747. NSLog(@"%@",dateStr);
  748. NSString *content = [[NSString stringWithFormat:@"%@_%@",phone,dateStr] stringByAppendingString:[NSString stringWithFormat:@"_%@",[LXMD5 md532BitLower:[NSString stringWithFormat:@"%@&%@",phone,dateStr]]]];
  749. NSData *contentData = [content dataUsingEncoding:NSUTF8StringEncoding];
  750. NSUInteger dataLength = contentData.length;
  751. // 为结束符'\\0' +1
  752. char keyPtr[new_kKeySize + 1];
  753. memset(keyPtr, 0, sizeof(keyPtr));
  754. [new_AesKey getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
  755. // 密文长度 <= 明文长度 + BlockSize
  756. size_t encryptSize = dataLength + kCCBlockSizeAES128;
  757. void *encryptedBytes = malloc(encryptSize);
  758. size_t actualOutSize = 0;
  759. NSData *initVector = [new_kInitVector dataUsingEncoding:NSUTF8StringEncoding];
  760. CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt,
  761. kCCAlgorithmAES,
  762. kCCOptionPKCS7Padding, // 系统默认使用 CBC,然后指明使用 PKCS7Padding
  763. keyPtr,
  764. new_kKeySize,
  765. initVector.bytes,
  766. contentData.bytes,
  767. dataLength,
  768. encryptedBytes,
  769. encryptSize,
  770. &actualOutSize);
  771. if (cryptStatus == kCCSuccess) {
  772. // 对加密后的数据进行 base64 编码
  773. return [[NSData dataWithBytesNoCopy:encryptedBytes length:actualOutSize] base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
  774. }
  775. free(encryptedBytes);
  776. return nil;
  777. }
  778. //js方法登录成功
  779. -(void)jsLoginSuccess:(NSDictionary *)dict {
  780. NSLog(@"search登录成功提示:%@",dict);
  781. NSString *status = [NSString stringWithFormat:@"%@",dict[@"status"]];
  782. [GlobalData shareInstance].isReLogin = YES;
  783. if([status isEqualToString:@"S"]) {
  784. [self webViewFirstRequest];
  785. }else if ([status isEqualToString:@""]) {
  786. //不刷新订阅-首页,刷新其他
  787. [[NSNotificationCenter defaultCenter] postNotificationName:RefreshExpAndMine object:nil userInfo:nil];
  788. }else {
  789. }
  790. //弹出页面
  791. if ([GlobalData shareInstance].isPasteLogin) {
  792. [GlobalData shareInstance].isPasteLogin = NO;
  793. NSString *content = [UIPasteboard generalPasteboard].string;
  794. [self popPasteVIew:content];
  795. }
  796. }
  797. -(void)jsBackUrl:(NSDictionary *)dict {
  798. [self webViewFirstRequest];
  799. }
  800. -(void)jsClearPushMessage:(NSDictionary *)dict {
  801. kMainQueue(^{
  802. [[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
  803. [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
  804. });
  805. }
  806. -(void)jsWxPay:(NSDictionary *)dict {
  807. if (![LXUserDefaults isInstallWeiXin]) { [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"请先安装微信再进行支付!" delay:1.5];
  808. return;
  809. }
  810. NSString *jsonString = [NSString stringWithFormat:@"%@",dict[@"order"]];
  811. NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
  812. NSError *err;
  813. NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
  814. if(err) {
  815. NSLog(@"json解析失败:%@",err);
  816. return;
  817. }
  818. //吊起微信
  819. PayReq *request = [[PayReq alloc] init] ;
  820. request.openID = dic[@"Appid"];
  821. request.partnerId = dic[@"Partnerid"];
  822. request.prepayId= dic[@"Prepayid"];
  823. request.package = @"Sign=WXPay";
  824. request.nonceStr= dic[@"Noncestr"];
  825. request.timeStamp= [dic[@"Timestamp"] intValue];
  826. request.sign= dic[@"Sign"];
  827. kMainQueue(^{
  828. [WXApi sendReq:request completion:^(BOOL success) {
  829. }];
  830. });
  831. }
  832. -(void)jsAliPay:(NSDictionary *)dict {
  833. if (![LXUserDefaults isInstallAli]) {
  834. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"请先安装支付宝再进行支付!" delay:1.5];
  835. return;
  836. }
  837. NSString *order = [NSString stringWithFormat:@"%@",dict[@"order"]];
  838. kMainQueue(^{
  839. [[AlipaySDK defaultService] payOrder:order fromScheme:@"jianyuiosapp" callback:nil];
  840. });
  841. }
  842. -(NSString *)jsGetOtherPushRid:(NSDictionary *)dict {
  843. return [LXUserDefaults deviceToken];
  844. }
  845. -(NSString *)jsGetPhoneBrand:(NSDictionary *)dict {
  846. UIDevice *device = [UIDevice currentDevice];
  847. return device.platformString;
  848. }
  849. -(NSString *)jsGetLocation:(NSDictionary *)dict {
  850. NSLog(@"------开始调用获取位置:%@",self.placeAdr);
  851. if (!self.isLocation) {
  852. // 1.检查定位服务是否开启
  853. if ([self checkLocationServiceIsEnabled]) {
  854. // 2.创建定位管理器:
  855. NSLog(@"定位可用");
  856. [self createCLManager];
  857. self.isLocation = YES; //只请求一次
  858. }else{
  859. NSLog(@"定位不可用");
  860. self.isLocation = NO;
  861. }
  862. //NSLog(@"即将返回城市信息-%@",self.placeAdr);
  863. }
  864. NSLog(@"即将返回城市信息-%@",self.placeAdr);
  865. //防止null nil情况
  866. if ([@"" isNotNULL:self.placeAdr]&&self.placeAdr.length>0&&[self.placeAdr isKindOfClass:[NSString class]]) {
  867. }else {
  868. self.placeAdr = @"";
  869. }
  870. return self.placeAdr;
  871. }
  872. -(NSString *)jsGetLLitude:(NSDictionary *)dict {
  873. NSLog(@"------开始调用获取经纬度:%@",self.placeLli);
  874. if (!self.isLocation) {
  875. if ([self checkLocationServiceIsEnabled]) {
  876. [self createCLManager];
  877. self.isLocation = YES; //只请求一次
  878. }else{
  879. NSLog(@"定位不可用");
  880. self.isLocation = NO;
  881. }
  882. }
  883. NSLog(@"即将返回经纬度信息-%@",self.placeLli);
  884. if ([@"" isNotNULL:self.placeLli]&&self.placeLli.length>0&&[self.placeLli isKindOfClass:[NSString class]]) {
  885. }else {
  886. self.placeLli = @"";
  887. }
  888. return self.placeLli;
  889. }
  890. //拍照上传图片
  891. -(void)jsSkipCameraWithParam:(NSDictionary *)dict {
  892. [GlobalData shareInstance].isSkipPath = [NSString stringWithFormat:@"%@",dict[@"type"]];
  893. UIImagePickerController *picker = [[UIImagePickerController alloc] init];
  894. picker.delegate = self;
  895. picker.allowsEditing = YES;
  896. picker.sourceType = UIImagePickerControllerSourceTypeCamera;
  897. dispatch_async(dispatch_get_main_queue(), ^{
  898. [self presentViewController:picker animated:YES completion:nil];
  899. });
  900. }
  901. //相册选择照片
  902. -(void)jsSkipAlbumWithParam:(NSDictionary *)dict {
  903. [GlobalData shareInstance].isSkipPath = [NSString stringWithFormat:@"%@",dict[@"type"]];
  904. UIImagePickerController *picker = [[UIImagePickerController alloc] init];
  905. picker.delegate = self;
  906. picker.allowsEditing = YES;
  907. picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  908. dispatch_async(dispatch_get_main_queue(), ^{
  909. [self presentViewController:picker animated:YES completion:nil];
  910. });
  911. }
  912. //统计点击推送
  913. -(void)jsOpenActivityPage:(NSDictionary *)dict {
  914. NSDictionary * infoDic = @{@"url":[NSString stringWithFormat:@"%@",dict[@"url"]],
  915. @"rectype":[NSString stringWithFormat:@"%@",dict[@"rectype"]],
  916. @"openid":[NSString stringWithFormat:@"%@",dict[@"openid"]],
  917. };
  918. //post请求
  919. NSLog(@"%@",[NSString stringWithFormat:@"%@jyapp/free/message/receive",kHost]);
  920. [[LXNetworkManager shareLXNetworkManager]postWithURLStr:[NSString stringWithFormat:@"%@jyapp/free/message/receive",kHost] parameters:infoDic progress:^(NSProgress *progress) {
  921. NSLog(@"成功:%@",progress);
  922. } success:^(id responseObject) {
  923. NSLog(@"responseObject=%@",responseObject);
  924. } failure:^(NSError *error) {
  925. NSLog(@"error=%@",error);
  926. }];
  927. }
  928. //拨打电话
  929. -(void)jsCallPhone:(NSDictionary *)dict {
  930. NSString *phone = [NSString stringWithFormat:@"%@",dict[@"phone"]];
  931. NSMutableString *tel = [[NSMutableString alloc]initWithFormat:@"telprompt://%@",phone];
  932. if (@available(iOS 10.0, *)) {
  933. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:tel] options:@{} completionHandler:^(BOOL success) {
  934. }];
  935. } else {
  936. // Fallback on earlier versions
  937. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:tel]];
  938. }
  939. }
  940. //打开其他app 抖音+快手
  941. -(void)jsOpenOtherAppLinks:(NSDictionary *)dict {
  942. //测试跳转抖音--快手 @"gifshow://" @"snssdk1128://"
  943. NSString *appLink = [NSString stringWithFormat:@"%@",dict[@"appLink"]];
  944. NSString *appName = [NSString stringWithFormat:@"%@",dict[@"appName"]];
  945. NSLog(@"appName:%@",appName);
  946. NSURL *url = [NSURL URLWithString:appLink];
  947. if ([[UIApplication sharedApplication] canOpenURL:url]) {
  948. if ([[UIApplication sharedApplication] respondsToSelector:@selector(openURL:options:completionHandler:)]) {
  949. //iOS 10.0+
  950. NSLog(@"iOS 10+");
  951. if (@available(iOS 10.0, *)) {
  952. [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
  953. if (!success) {
  954. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:appName delay:2];
  955. }
  956. }];
  957. } else {
  958. // Fallback on earlier versions
  959. [[UIApplication sharedApplication] openURL:url];
  960. }
  961. }else{
  962. NSLog(@"iOS 2~10");
  963. //iOS 2~10
  964. [[UIApplication sharedApplication] openURL:url];
  965. }
  966. }else{
  967. //一般是没有安装
  968. NSLog(@"跳转下载app链接");
  969. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:appName delay:2];
  970. }
  971. }
  972. //保存图片到相册
  973. #pragma mark 保存图片
  974. -(void)jsSavePic:(NSDictionary *)dict {
  975. NSString *base64ImgData = [NSString stringWithFormat:@"%@",dict[@"imgbase64"]];
  976. base64ImgData = [base64ImgData stringByReplacingOccurrencesOfString:@"data:image/png;base64," withString:@""];
  977. NSData *data = [[NSData alloc]initWithBase64EncodedString:base64ImgData options:NSDataBase64DecodingIgnoreUnknownCharacters];
  978. UIImage *saveImg = [UIImage imageWithData:data];
  979. UIImageWriteToSavedPhotosAlbum(saveImg, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
  980. }
  981. #pragma mark 系统的完成保存图片的方法
  982. - (void)image: (UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo
  983. {
  984. NSString *msg = nil ;
  985. if (error != NULL) {
  986. msg = @"保存图片失败" ;
  987. } else {
  988. msg = @"保存图片成功" ;
  989. }
  990. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:msg delay:1];
  991. }
  992. #pragma mark 粘贴板
  993. -(void)jsWirteRight:(NSDictionary *)dict {
  994. NSString *txt = [NSString stringWithFormat:@"%@",dict[@"txt"]];
  995. [[UIPasteboard generalPasteboard]setString:txt];
  996. }
  997. -(void)jsClearRight:(NSDictionary *)dict {
  998. //清粘贴板数据
  999. [[UIPasteboard generalPasteboard]setString:@""];
  1000. }
  1001. -(NSString *)jsReadRight:(NSDictionary *)dict {
  1002. NSString *content = [UIPasteboard generalPasteboard].string;
  1003. return content;
  1004. }
  1005. //返回定位可用信息
  1006. -(int)jsCheckLocationPermission:(NSDictionary *)dict {
  1007. if ([CLLocationManager locationServicesEnabled]) {
  1008. if ([CLLocationManager authorizationStatus]!= kCLAuthorizationStatusDenied) {
  1009. if ([CLLocationManager authorizationStatus]==kCLAuthorizationStatusNotDetermined) {
  1010. return -1;
  1011. }
  1012. return 1;
  1013. }
  1014. }
  1015. return 0;
  1016. }
  1017. //内购VIP
  1018. -(void)jsInPurchasingVip:(NSDictionary *)dict {
  1019. NSString *productid = [NSString stringWithFormat:@"%@",dict[@"productid"]];
  1020. //产品id
  1021. if ([productid isEqualToString:@""]) {
  1022. NSLog(@"订单号 有问题");
  1023. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"订单号异常,请重试" delay:1];
  1024. return;
  1025. }
  1026. [[LXViewControllerManager shareViewControllerManager] showHudText:@"苹果验证中,请稍候"];
  1027. //监听购买结果
  1028. if([SKPaymentQueue canMakePayments]){
  1029. [self requestProductData:productid];
  1030. }else{
  1031. NSLog(@"不允许程序内付费");
  1032. [[LXViewControllerManager shareViewControllerManager] hideHud];
  1033. }
  1034. }
  1035. //去苹果服务器请求商品
  1036. - (void)requestProductData:(NSString *)type {
  1037. NSArray *product = [[NSArray alloc] initWithObjects:type,nil];
  1038. NSSet *nsset = [NSSet setWithArray:product];
  1039. SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:nsset];
  1040. request.delegate = self;
  1041. [request start];
  1042. }
  1043. - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
  1044. NSArray *myProduct = response.products;
  1045. if (myProduct.count == 0) {
  1046. NSLog(@"无法获取产品信息,购买失败。");
  1047. [[LXViewControllerManager shareViewControllerManager]showHudOnlyText:@"暂时未获取到产品信息,请重试" delay:1];
  1048. return;
  1049. }
  1050. SKPayment * payment = [SKPayment paymentWithProduct:myProduct[0]];
  1051. [[SKPaymentQueue defaultQueue] addPayment:payment];
  1052. }
  1053. //监听购买结果
  1054. - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
  1055. NSLog(@"收到支付回调");
  1056. for (SKPaymentTransaction *transaction in transactions) {
  1057. switch (transaction.transactionState) {
  1058. case SKPaymentTransactionStatePurchased://交易完成
  1059. NSLog(@"购买成功transactionIdentifier = %@", transaction.transactionIdentifier);
  1060. [self completeTransaction:transaction];
  1061. break;
  1062. case SKPaymentTransactionStateFailed://交易失败
  1063. [self failedTransaction:transaction];
  1064. break;
  1065. case SKPaymentTransactionStateRestored://已经购买过该商品
  1066. [self restoreTransaction:transaction];
  1067. break;
  1068. case SKPaymentTransactionStatePurchasing://商品添加进列表
  1069. NSLog(@"商品添加进列表");
  1070. break;
  1071. default:
  1072. break;
  1073. }
  1074. }
  1075. }
  1076. - (void)completeTransaction:(SKPaymentTransaction *)transaction {
  1077. // Your application should implement these two methods.
  1078. [[LXViewControllerManager shareViewControllerManager] hideHud];
  1079. NSString * productIdentifier = transaction.payment.productIdentifier;
  1080. NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[[NSBundle mainBundle] appStoreReceiptURL]];
  1081. NSData *receiptData;
  1082. NSError *error = nil;
  1083. receiptData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:nil error:&error];
  1084. NSString *receipt = [receiptData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
  1085. if ([productIdentifier length] > 0) {
  1086. // 向自己的服务器验证购买凭证
  1087. if(self.tabBarController.selectedIndex == 0) {
  1088. [self isExitCallToJS:[NSString stringWithFormat:@"getReceipt('%@')", receipt] withMethodName:@"getReceipt"];
  1089. }else {
  1090. [[NSNotificationCenter defaultCenter] postNotificationName:@"receiptData" object:nil userInfo:@{@"receipt":receipt}];
  1091. }
  1092. }
  1093. // Remove the transaction from the payment queue.
  1094. [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
  1095. }
  1096. - (void)failedTransaction:(SKPaymentTransaction *)transaction {
  1097. [[LXViewControllerManager shareViewControllerManager] hideHud];
  1098. if(transaction.error.code != SKErrorPaymentCancelled) {
  1099. NSLog(@"购买失败");
  1100. [[LXViewControllerManager shareViewControllerManager]showHudOnlyText:@"购买失败,请重新尝试。" delay:1];
  1101. } else {
  1102. NSLog(@"用户取消交易");
  1103. [[LXViewControllerManager shareViewControllerManager]showHudOnlyText:@"取消交易" delay:1];
  1104. }
  1105. [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
  1106. }
  1107. - (void)restoreTransaction:(SKPaymentTransaction *)transaction {
  1108. // 对于已购商品,处理恢复购买的逻辑
  1109. NSLog(@"对于已购商品,处理恢复购买的逻辑");
  1110. [[LXViewControllerManager shareViewControllerManager] hideHud];
  1111. [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
  1112. }
  1113. -(void)jsDownLoadFile:(NSDictionary *)dict {
  1114. NSString *filename = [NSString stringWithFormat:@"%@",dict[@"filename"]];
  1115. NSString *filetype = [NSString stringWithFormat:@"%@",dict[@"filetype"]];
  1116. NSString *fileurl = [NSString stringWithFormat:@"%@",dict[@"fileurl"]];
  1117. NSString *filesize = [NSString stringWithFormat:@"%@",dict[@"filesize"]];
  1118. NSString *new_filename = [NSString stringWithFormat:@"%@.%@",[filename stringByRemovingPercentEncoding],filetype];
  1119. new_filename=[new_filename stringByReplacingOccurrencesOfString:@"/" withString:@""];
  1120. LoadDocViewController *load = [[LoadDocViewController alloc] init];
  1121. JhtFileModel *fileModel = [[JhtFileModel alloc] init];
  1122. fileModel.fileName = new_filename;
  1123. if ([filetype isEqualToString:@"doc"] || [filetype isEqualToString:@"word"]||[filetype isEqualToString:@"docx"]) {
  1124. fileModel.viewFileType =Type_Docx;
  1125. }else if([filetype isEqualToString:@"excel"]||[filetype isEqualToString:@"xls"]||[filetype isEqualToString:@"xlsx"]) {
  1126. fileModel.viewFileType =Type_Xlsx;
  1127. }else if([filetype isEqualToString:@"ppt"]||[filetype isEqualToString:@"pptx"]) {
  1128. fileModel.viewFileType =Type_Pptx;
  1129. }else if([filetype isEqualToString:@"pdf"]) {
  1130. fileModel.viewFileType =Type_Pdf;
  1131. }else if([filetype isEqualToString:@"txt"]) {
  1132. fileModel.viewFileType =Type_Txt;
  1133. }else if([filetype isEqualToString:@"jpg"]||[filetype isEqualToString:@"JPG"]||[filetype isEqualToString:@"jpeg"]) {
  1134. fileModel.viewFileType =Type_Jpg;
  1135. }else if([filetype isEqualToString:@"png"]||[filetype isEqualToString:@"PNG"]) {
  1136. fileModel.viewFileType =Type_Png;
  1137. }else {
  1138. fileModel.viewFileType =Type_Unknow;
  1139. }
  1140. fileModel.url = fileurl;
  1141. fileModel.fileSize = filesize;
  1142. load.titleStr = fileModel.fileName;
  1143. load.currentFileModel = fileModel;
  1144. kMainQueue(^{
  1145. [self presentViewController:load animated:YES completion:nil];
  1146. });
  1147. }
  1148. //清除历史返回列表
  1149. -(void)jsClearHistory:(NSDictionary *)dict {
  1150. [_webView.backForwardList performSelector:NSSelectorFromString(@"_removeAllItems")];
  1151. }
  1152. //开启侧滑
  1153. -(void)jsSideslipOpen:(NSDictionary *)dict {
  1154. self.isCanBack = YES;
  1155. }
  1156. //关闭侧滑
  1157. -(void)jsSideslipClose:(NSDictionary *)dict {
  1158. self.isCanBack = NO;
  1159. }
  1160. //返回登录有效
  1161. -(void)jsCheckLoginEnvAvailable:(NSDictionary *)dict {
  1162. __block BOOL support = NO;
  1163. __block NSString *sup = @"0";
  1164. [[TXCommonHandler sharedInstance] checkEnvAvailableWithAuthType:PNSAuthTypeLoginToken complete:^(NSDictionary * _Nullable resultDic) {
  1165. support = [PNSCodeSuccess isEqualToString:[resultDic objectForKey:@"resultCode"]];
  1166. if (support){
  1167. sup = @"1";
  1168. }
  1169. [self isExitCallToJS:[NSString stringWithFormat:@"checkLoginEnvAvailableCallback('%@')",sup] withMethodName:@"checkLoginEnvAvailableCallback"];
  1170. }];
  1171. }
  1172. -(void)jsGetLogin:(NSDictionary *)dict {
  1173. TXCustomModel *model = [[TXCustomModel alloc] init];
  1174. model.supportedInterfaceOrientations = UIInterfaceOrientationMaskPortrait;
  1175. //导航栏配置
  1176. model.navColor = UIColor.whiteColor;
  1177. NSDictionary *attributes = @{
  1178. NSForegroundColorAttributeName : [UIColor whiteColor],
  1179. NSFontAttributeName : [UIFont systemFontOfSize:18.0]
  1180. };
  1181. model.navTitle = [[NSAttributedString alloc] initWithString:@"" attributes:attributes];
  1182. model.navBackImage = [UIImage imageNamed:@"arrowLeft"];
  1183. //logo配置
  1184. model.logoImage = [UIImage imageNamed:@"logo"];
  1185. model.logoFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  1186. return CGRectMake((WIDTH-80)*0.5, 30, 80, 80);
  1187. };
  1188. model.numberColor = UIColorFromRGB(0x171826);
  1189. model.numberFont = [UIFont systemFontOfSize:24.0];
  1190. model.numberFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  1191. frame.origin.y = 110+30;
  1192. return frame;
  1193. };
  1194. model.sloganFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  1195. frame.origin.y = 150+30;
  1196. return frame;
  1197. };
  1198. model.loginBtnText = [[NSAttributedString alloc] initWithString:@"一键登录/注册" attributes:@{NSForegroundColorAttributeName : UIColor.whiteColor,NSFontAttributeName : [UIFont systemFontOfSize:18.0]}];
  1199. NSArray *BtnBgImgs = [NSArray arrayWithObjects:[UIImage imageNamed:@"authbtn_nor"],[UIImage imageNamed:@"authbtn_dis"],[UIImage imageNamed:@"authbtn_nor"], nil];
  1200. model.loginBtnBgImgs = BtnBgImgs;
  1201. model.changeBtnTitle = [[NSAttributedString alloc] initWithString:@"其他手机号登录/注册" attributes:@{NSForegroundColorAttributeName : UIColorFromRGB(0x2ABED1),NSFontAttributeName : [UIFont systemFontOfSize:16.0]}];
  1202. model.changeBtnFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  1203. return CGRectMake(10, frame.origin.y, WIDTH - 20, 30);
  1204. };
  1205. model.preferredStatusBarStyle = UIStatusBarStyleLightContent;
  1206. model.privacyNavBackImage = [UIImage imageNamed:@"arrowLeft"];
  1207. NSArray *boxImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"unchoose"],[UIImage imageNamed:@"choose"], nil];
  1208. model.checkBoxImages = boxImages;
  1209. model.privacyColors = @[UIColor.blackColor, UIColorFromRGB(0x2ABED1)];
  1210. model.privacyAlignment = NSTextAlignmentCenter;
  1211. model.privacyFont = [UIFont fontWithName:@"PingFangSC-Regular" size:13.0];
  1212. model.privacyOperatorPreText = @"《";
  1213. model.privacyOperatorSufText = @"》";
  1214. model.privacyPreText = @"已阅读并同意";
  1215. NSString *onePrivacy = [NSString stringWithFormat:@"%@jyapp/free/staticPage/permission_rules.html",kHost];
  1216. NSString *twoPrivacy = [NSString stringWithFormat:@"%@/jyapp/free/staticPage/privacy_rules.html",kHost];
  1217. model.privacyOne = [NSArray arrayWithObjects:@"《使用协议》",onePrivacy,nil];
  1218. model.privacyTwo = [NSArray arrayWithObjects:@"《隐私政策》",twoPrivacy, nil];
  1219. [[TXCommonHandler sharedInstance] getLoginTokenWithTimeout:3.0 controller:self model:model complete:^(NSDictionary * _Nonnull resultDic) {
  1220. // NSLog(@"一键登录结果:%@", resultDic);
  1221. NSString *code = [resultDic objectForKey:@"resultCode"];
  1222. if ([PNSCodeLoginControllerPresentSuccess isEqualToString:code]) {
  1223. NSLog(@"弹起授权页成功");
  1224. [self isExitCallToJS:[NSString stringWithFormat:@"getLoginCallback('%@')",[self convertToJsonData:resultDic]] withMethodName:@"getLoginCallback"];
  1225. } else if ([PNSCodeLoginControllerClickCancel isEqualToString:code]) {
  1226. NSLog(@"点击了授权页的返回");
  1227. [self isExitCallToJS:[NSString stringWithFormat:@"getLoginCallback('%@')",[self convertToJsonData:resultDic]] withMethodName:@"getLoginCallback"];
  1228. } else if ([PNSCodeLoginControllerClickChangeBtn isEqualToString:code]) {
  1229. NSLog(@"点击切换其他登录方式按钮");
  1230. [self isExitCallToJS:[NSString stringWithFormat:@"getLoginCallback('%@')",[self convertToJsonData:resultDic]] withMethodName:@"getLoginCallback"];
  1231. dispatch_async(dispatch_get_main_queue(), ^{
  1232. [[TXCommonHandler sharedInstance] cancelLoginVCAnimated:YES complete:nil];
  1233. });
  1234. } else if ([PNSCodeLoginControllerClickLoginBtn isEqualToString:code]) {
  1235. if ([[resultDic objectForKey:@"isChecked"] boolValue] == YES) {
  1236. NSLog(@"已勾选···点击登录···");
  1237. } else {
  1238. NSLog(@"未勾选···点击登录···");
  1239. }
  1240. } else if ([PNSCodeLoginControllerClickCheckBoxBtn isEqualToString:code]) {
  1241. NSLog(@"点击check box");
  1242. } else if ([PNSCodeLoginControllerClickProtocol isEqualToString:code]) {
  1243. NSLog(@"点击了协议富文本");
  1244. } else if ([PNSCodeSuccess isEqualToString:code]) {
  1245. //点击登录按钮获取登录Token成功回调
  1246. [self isExitCallToJS:[NSString stringWithFormat:@"getLoginCallback('%@')",[self convertToJsonData:resultDic]] withMethodName:@"getLoginCallback"];
  1247. dispatch_async(dispatch_get_main_queue(), ^{
  1248. [[TXCommonHandler sharedInstance] cancelLoginVCAnimated:YES complete:nil];
  1249. });
  1250. } else {
  1251. NSLog(@"获取登录Token失败");
  1252. [self isExitCallToJS:[NSString stringWithFormat:@"getLoginCallback('%@')",[self convertToJsonData:resultDic]] withMethodName:@"getLoginCallback"];
  1253. }
  1254. }];
  1255. }
  1256. -(void)jsGetPhoneBind:(NSDictionary *)dict {
  1257. TXCustomModel *model = [[TXCustomModel alloc] init];
  1258. model.supportedInterfaceOrientations = UIInterfaceOrientationMaskPortrait;
  1259. //导航栏配置
  1260. model.navColor = UIColor.whiteColor;
  1261. NSDictionary *attributes = @{
  1262. NSForegroundColorAttributeName : [UIColor blackColor],
  1263. NSFontAttributeName : [UIFont systemFontOfSize:18.0]
  1264. };
  1265. model.navTitle = [[NSAttributedString alloc] initWithString:@"绑定手机号" attributes:attributes];
  1266. model.navBackImage = [UIImage imageNamed:@"arrowLeft"];
  1267. //logo配置
  1268. model.logoIsHidden = YES;
  1269. // model.logoImage = [UIImage imageNamed:@""];
  1270. // model.logoFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  1271. // return CGRectMake((WIDTH-80)*0.5, 30, 80, 80);
  1272. // };
  1273. model.numberColor = UIColorFromRGB(0x171826);
  1274. model.numberFont = [UIFont systemFontOfSize:24.0];
  1275. model.numberFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  1276. frame.origin.y = 110+30;
  1277. return frame;
  1278. };
  1279. model.sloganFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  1280. frame.origin.y = 150+30;
  1281. return frame;
  1282. };
  1283. model.loginBtnText = [[NSAttributedString alloc] initWithString:@"一键绑定手机号" attributes:@{NSForegroundColorAttributeName : UIColor.whiteColor,NSFontAttributeName : [UIFont systemFontOfSize:18.0]}];
  1284. NSArray *BtnBgImgs = [NSArray arrayWithObjects:[UIImage imageNamed:@"authbtn_nor"],[UIImage imageNamed:@"authbtn_dis"],[UIImage imageNamed:@"authbtn_nor"], nil];
  1285. model.loginBtnBgImgs = BtnBgImgs;
  1286. model.changeBtnTitle = [[NSAttributedString alloc] initWithString:@"绑定其他手机号" attributes:@{NSForegroundColorAttributeName : UIColorFromRGB(0x2ABED1),NSFontAttributeName : [UIFont systemFontOfSize:16.0]}];
  1287. model.changeBtnFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  1288. return CGRectMake(10, frame.origin.y, WIDTH - 20, 30);
  1289. };
  1290. model.preferredStatusBarStyle = UIStatusBarStyleLightContent;
  1291. model.privacyNavBackImage = [UIImage imageNamed:@"arrowLeft"];
  1292. NSArray *boxImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"unchoose"],[UIImage imageNamed:@"choose"], nil];
  1293. model.checkBoxImages = boxImages;
  1294. model.privacyColors = @[UIColor.blackColor, UIColorFromRGB(0x2ABED1)];
  1295. model.privacyAlignment = NSTextAlignmentCenter;
  1296. model.privacyFont = [UIFont fontWithName:@"PingFangSC-Regular" size:13.0];
  1297. model.privacyOperatorPreText = @"《";
  1298. model.privacyOperatorSufText = @"》";
  1299. model.privacyPreText = @"已阅读并同意";
  1300. [[TXCommonHandler sharedInstance] getLoginTokenWithTimeout:3.0 controller:self model:model complete:^(NSDictionary * _Nonnull resultDic) {
  1301. // NSLog(@"一键登录结果:%@", resultDic);
  1302. NSString *code = [resultDic objectForKey:@"resultCode"];
  1303. if ([PNSCodeLoginControllerPresentSuccess isEqualToString:code]) {
  1304. NSLog(@"弹起授权页成功");
  1305. [self isExitCallToJS:[NSString stringWithFormat:@"getPhoneBindCallback('%@')",[self convertToJsonData:resultDic]] withMethodName:@"getPhoneBindCallback"];
  1306. } else if ([PNSCodeLoginControllerClickCancel isEqualToString:code]) {
  1307. NSLog(@"点击了授权页的返回");
  1308. [self isExitCallToJS:[NSString stringWithFormat:@"getPhoneBindCallback('%@')",[self convertToJsonData:resultDic]] withMethodName:@"getPhoneBindCallback"];
  1309. } else if ([PNSCodeLoginControllerClickChangeBtn isEqualToString:code]) {
  1310. NSLog(@"点击切换其他登录方式按钮");
  1311. [self isExitCallToJS:[NSString stringWithFormat:@"getPhoneBindCallback('%@')",[self convertToJsonData:resultDic]] withMethodName:@"getPhoneBindCallback"];
  1312. dispatch_async(dispatch_get_main_queue(), ^{
  1313. [[TXCommonHandler sharedInstance] cancelLoginVCAnimated:YES complete:nil];
  1314. });
  1315. } else if ([PNSCodeLoginControllerClickLoginBtn isEqualToString:code]) {
  1316. if ([[resultDic objectForKey:@"isChecked"] boolValue] == YES) {
  1317. NSLog(@"已勾选···点击登录···");
  1318. } else {
  1319. NSLog(@"未勾选···点击登录···");
  1320. }
  1321. } else if ([PNSCodeLoginControllerClickCheckBoxBtn isEqualToString:code]) {
  1322. NSLog(@"点击check box");
  1323. } else if ([PNSCodeLoginControllerClickProtocol isEqualToString:code]) {
  1324. NSLog(@"点击了协议富文本");
  1325. } else if ([PNSCodeSuccess isEqualToString:code]) {
  1326. //点击登录按钮获取登录Token成功回调
  1327. NSString *token = [resultDic objectForKey:@"token"];
  1328. NSLog(@"成功获取Token:%@",token);
  1329. [self isExitCallToJS:[NSString stringWithFormat:@"getPhoneBindCallback('%@')",[self convertToJsonData:resultDic]] withMethodName:@"getPhoneBindCallback"];
  1330. dispatch_async(dispatch_get_main_queue(), ^{
  1331. [[TXCommonHandler sharedInstance] cancelLoginVCAnimated:YES complete:nil];
  1332. });
  1333. } else {
  1334. NSLog(@"获取登录Token失败");
  1335. [self isExitCallToJS:[NSString stringWithFormat:@"getPhoneBindCallback('%@')",[self convertToJsonData:resultDic]] withMethodName:@"getPhoneBindCallback"];
  1336. }
  1337. }];
  1338. }
  1339. #pragma mark *****其他方法
  1340. - (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script
  1341. {
  1342. __block NSString *resultString = @"";
  1343. __block BOOL finished = NO;
  1344. [self.webView evaluateJavaScript:script completionHandler:^(id result, NSError *error) {
  1345. if (error == nil) {
  1346. if (result != nil) {
  1347. resultString = [NSString stringWithFormat:@"%@", result];
  1348. }
  1349. } else {
  1350. NSLog(@"evaluateJavaScript error : %@", error.localizedDescription);
  1351. }
  1352. finished = YES;
  1353. }];
  1354. while (!finished) {
  1355. [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
  1356. }
  1357. return resultString;
  1358. }
  1359. //取消获取照片
  1360. - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
  1361. {
  1362. dispatch_async(dispatch_get_main_queue(), ^{
  1363. [picker dismissViewControllerAnimated:YES completion:^{
  1364. [self uploadUrl:@""];
  1365. }];
  1366. });
  1367. }
  1368. //上传图片
  1369. -(void)uploadPic:(NSData *)data
  1370. {
  1371. NSString *isPath = @"courseFile";
  1372. if (![[GlobalData shareInstance].isSkipPath isEqualToString:@""]) {
  1373. isPath = [GlobalData shareInstance].isSkipPath;
  1374. }
  1375. NSDictionary * body = @{@"type":isPath};
  1376. AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
  1377. //ContentType设置
  1378. manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html",@"image/jpeg",@"image/png",@"application/octet-stream",@"text/json",@"text/plain",nil];
  1379. manager.responseSerializer= [AFHTTPResponseSerializer serializer];
  1380. manager.requestSerializer = [AFHTTPRequestSerializer serializer];
  1381. manager.requestSerializer.timeoutInterval = 15.0f;
  1382. [manager POST:[NSString stringWithFormat:@"%@jyapp/filemanage/upload",kHost] parameters:body constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
  1383. //上传的参数(上传图片,以文件流的格式)
  1384. [formData appendPartWithFileData:data
  1385. name:isPath
  1386. fileName:[isPath stringByAppendingFormat:@".jpeg"]
  1387. mimeType:@"image/jpeg"];
  1388. } progress:^(NSProgress * _Nonnull uploadProgress) {
  1389. CGFloat progress = 100.0 * uploadProgress.completedUnitCount / uploadProgress.totalUnitCount;
  1390. NSLog(@"%.2lf%%", progress);
  1391. } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
  1392. //请求成功的block回调
  1393. NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
  1394. NSLog(@"上传成功%@",dic);
  1395. if ([dic[@"msg"] isEqualToString:@"ssss"]) {
  1396. [self uploadUrl:dic[@"url"]];
  1397. }else{
  1398. [self uploadUrl:@""];
  1399. }
  1400. } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
  1401. NSLog(@"上传失败%@",error);
  1402. [self uploadUrl:@""];
  1403. }];
  1404. }
  1405. -(void)uploadUrl:(NSString *)url {
  1406. NSString *textJS = [NSString new];
  1407. NSString *methodJS = [NSString new];
  1408. if ([url isEqualToString:@""]) {
  1409. textJS = @"hiddenLoading()";
  1410. methodJS =@"hiddenLoading";
  1411. }else{
  1412. textJS = [NSString stringWithFormat:@"uploadImg('%@')",url];
  1413. methodJS = @"uploadImg";
  1414. }
  1415. if ([url isEqualToString:@""]||[textJS isEqualToString:@""]) {
  1416. NSLog(@"空的情况");
  1417. textJS = @"hiddenLoading()";
  1418. methodJS = @"hiddenLoading";
  1419. }
  1420. NSDictionary *dict = @{@"jsStr":textJS,@"name":methodJS};
  1421. [self performSelector:@selector(uploadJS:) withObject:dict afterDelay:1];
  1422. }
  1423. //获取到图片
  1424. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
  1425. {
  1426. dispatch_async(dispatch_get_main_queue(), ^{
  1427. [picker dismissViewControllerAnimated:YES completion:^{
  1428. UIImage * img=[info objectForKey:UIImagePickerControllerEditedImage];
  1429. NSData *data = UIImageJPEGRepresentation(img, 0.5);
  1430. if (data!=nil) {
  1431. [self uploadPic:data];
  1432. }else{
  1433. NSLog(@"data == nil");
  1434. [self uploadUrl:@""];
  1435. }
  1436. }];
  1437. });
  1438. }
  1439. -(void)uploadJS:(NSDictionary *)dict {
  1440. [self isExitCallToJS:dict[@"jsStr"] withMethodName:dict[@"name"]];
  1441. }
  1442. - (BOOL)checkLocationServiceIsEnabled{
  1443. // 该方法是类方法,和我们创建的管理器没有关系
  1444. if ([CLLocationManager locationServicesEnabled]) {
  1445. return YES;
  1446. }
  1447. return NO;
  1448. }
  1449. - (void)createCLManager{
  1450. // 创建CoreLocation管理对象
  1451. self.locaationManager = [[CLLocationManager alloc]init];
  1452. // 设定定位精准度
  1453. [self.locaationManager setDesiredAccuracy:kCLLocationAccuracyBest];
  1454. // 设定DistanceFilter可以在用户移动指定距离之后触发更新事件(100米更新一次)
  1455. [self.locaationManager setDistanceFilter:1.f];
  1456. // 设置代理
  1457. self.locaationManager.delegate = self;
  1458. // 开始更新定位
  1459. [self.locaationManager startUpdatingLocation];
  1460. }
  1461. // 代理方法,更新位置
  1462. - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations{
  1463. CLLocation * newLocation = [locations lastObject];
  1464. // 判空处理
  1465. if (newLocation.horizontalAccuracy < 0) {
  1466. return;
  1467. }
  1468. self.placeLli = [NSString stringWithFormat:@"%f_%f",newLocation.coordinate.longitude,newLocation.coordinate.latitude];
  1469. NSLog(@"回调经纬度:%@",self.placeLli);
  1470. CLGeocoder *geocoder = [[CLGeocoder alloc] init];
  1471. [geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
  1472. for (CLPlacemark *placeMark in placemarks) {
  1473. //NSLog(@"位置:%@", placeMark.name);
  1474. //NSLog(@"街道:%@", placeMark.thoroughfare);
  1475. //NSLog(@"子街道:%@", placeMark.subThoroughfare);
  1476. //NSLog(@"区\\县:%@", placeMark.subLocality);
  1477. //NSLog(@"市:%@", placeMark.locality);
  1478. //NSLog(@"行政区:%@", placeMark.administrativeArea);
  1479. //NSLog(@"国家:%@", placeMark.country);
  1480. self.placeAdr = [placeMark.administrativeArea stringByAppendingString:[NSString stringWithFormat:@"-%@",placeMark.locality]];
  1481. }
  1482. }];
  1483. }
  1484. // 代理方法,定位权限检查
  1485. -(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{
  1486. switch (status) {
  1487. case kCLAuthorizationStatusNotDetermined:{
  1488. NSLog(@"用户还未决定授权");
  1489. // 主动获得授权
  1490. [self.locaationManager requestWhenInUseAuthorization];
  1491. break;
  1492. }
  1493. case kCLAuthorizationStatusRestricted:
  1494. {
  1495. NSLog(@"访问受限");
  1496. // 主动获得授权
  1497. [self.locaationManager requestWhenInUseAuthorization];
  1498. break;
  1499. }
  1500. case kCLAuthorizationStatusDenied:{
  1501. // 此时使用主动获取方法也不能申请定位权限
  1502. // 类方法,判断是否开启定位服务
  1503. if ([CLLocationManager locationServicesEnabled]) {
  1504. NSLog(@"定位服务开启,被拒绝");
  1505. } else {
  1506. NSLog(@"定位服务关闭,不可用");
  1507. }
  1508. break;
  1509. }
  1510. case kCLAuthorizationStatusAuthorizedAlways:{
  1511. NSLog(@"获得前后台授权");
  1512. break;
  1513. }
  1514. case kCLAuthorizationStatusAuthorizedWhenInUse:{
  1515. NSLog(@"获得前台授权");
  1516. break;
  1517. }
  1518. default:
  1519. break;
  1520. }
  1521. }
  1522. -(NSString *)convertToJsonData:(NSDictionary *)dict {
  1523. NSError *error;
  1524. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
  1525. NSString *jsonString;
  1526. if (!jsonData) {
  1527. NSLog(@"%@",error);
  1528. }else{
  1529. jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
  1530. }
  1531. NSMutableString *mutStr = [NSMutableString stringWithString:jsonString];
  1532. NSRange range = {0,jsonString.length};
  1533. //去掉字符串中的空格
  1534. [mutStr replaceOccurrencesOfString:@" " withString:@"" options:NSLiteralSearch range:range];
  1535. NSRange range2 = {0,mutStr.length};
  1536. //去掉字符串中的换行符
  1537. [mutStr replaceOccurrencesOfString:@"\n" withString:@"" options:NSLiteralSearch range:range2];
  1538. return mutStr;
  1539. }
  1540. -(void)addNoNetViews{
  1541. kMainQueue(^{
  1542. self.recognizer.enabled = NO;
  1543. [self removeNoNetViews];
  1544. //about:blank
  1545. self.noNetView = [NoNetView shareView];
  1546. [self.view addSubview:self.noNetView];
  1547. });
  1548. }
  1549. -(void)removeNoNetViews{
  1550. if (self.noNetView ) {
  1551. self.recognizer.enabled = YES;
  1552. [self.noNetView removeFromSuperview];
  1553. self.noNetView = nil;
  1554. }
  1555. }
  1556. -(void)addFailNetViews{
  1557. kMainQueue(^{
  1558. self.recognizer.enabled = NO;
  1559. [self removeFailNetViews];
  1560. self.failNetView = [NoNetView shareView];
  1561. [self.view addSubview:self.failNetView];
  1562. });
  1563. }
  1564. -(void)removeFailNetViews{
  1565. if (self.failNetView ) {
  1566. self.recognizer.enabled = YES;
  1567. [self.failNetView removeFromSuperview];
  1568. self.failNetView = nil;
  1569. }
  1570. }
  1571. #pragma mark **** 通知相关方法
  1572. -(void)openPushUrlOtherMethods:(NSNotification *)notification{
  1573. NSDictionary *infoDict = notification.userInfo;
  1574. if (!infoDict) {return;}
  1575. NSString * urlStr = [NSString stringWithFormat:@"%@",infoDict[@"url"]];
  1576. if ([urlStr isEqualToString:kHost]) {return;}
  1577. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]]];
  1578. }
  1579. -(void)openPushLinkUrlMethods:(NSNotification *)notification{
  1580. NSDictionary *infoDict = notification.userInfo;
  1581. NSLog(@"%@",infoDict);
  1582. if (!infoDict) {return;}
  1583. NSString * urlStr = [NSString stringWithFormat:@"%@",infoDict[@"url"]];
  1584. if ([urlStr isEqualToString:kHost]||![LXUserDefaults token]) {return;}
  1585. [self JsOpenExternalLink:@{@"url":urlStr,@"title":@"消息通知"}];
  1586. }
  1587. -(void)alipayWXpayStatus:(NSNotification *)notification{
  1588. NSString * status = [notification object];
  1589. [self performSelector:@selector(payStatus:) withObject:status afterDelay:2];
  1590. }
  1591. -(void)payStatus:(NSString *)status {
  1592. NSLog(@"支付状态:%@",status);//目前延时两秒
  1593. [self isExitCallToJS:[NSString stringWithFormat:@"payCallBack('%@')", status] withMethodName:@"payCallBack"];
  1594. }
  1595. // 再次加载页面
  1596. -(void)notNetReloadWebVIew:(NSNotification *)notification{
  1597. if (![self.webView canGoBack]) {
  1598. [self webViewFirstRequest];
  1599. }else{
  1600. [self.webView reload];
  1601. }
  1602. }
  1603. // 返回上一页面- 防止
  1604. -(void)popWebView:(NSNotification *)notification{
  1605. if ([self.webView canGoBack]) {
  1606. [self.webView goBack];
  1607. }
  1608. [self removeNoNetViews];
  1609. [self removeFailNetViews];
  1610. }
  1611. // 收到退出登录消息
  1612. -(void)loginOut:(NSNotification *)notification{
  1613. if([notification.userInfo[@"item_index"] integerValue]!=0) {
  1614. return;
  1615. }
  1616. NSString *url = [NSString stringWithFormat:@"%@%@", kHost, @"jyapp/free/login?back=index&isios=t&flag=kicked"];
  1617. url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  1618. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
  1619. }
  1620. // 监控网络状态变化
  1621. -(void)netReachChanged:(NSNotification *)notificaition{
  1622. NSDictionary *userInfo = notificaition.userInfo;
  1623. if ([userInfo[@"AFNetworkingReachabilityNotificationStatusItem"] intValue] == 0 || [userInfo[@"AFNetworkingReachabilityNotificationStatusItem"] intValue] == -1) {
  1624. // NSLog(@"检测无网络");
  1625. [self addNoNetViews];
  1626. }else{
  1627. [self removeNoNetViews];
  1628. if (isExistNoNewWork) {
  1629. isExistNoNewWork = NO;
  1630. [self notNetReloadWebVIew:nil];
  1631. }
  1632. }
  1633. }
  1634. //前往登录页面
  1635. -(void)isLoginTabBar:(NSNotification *)notification{
  1636. NSString *url = [NSString stringWithFormat:@"%@%@", kHost, @"jyapp/free/login"];
  1637. url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  1638. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
  1639. }
  1640. -(void)jyReceiveNewsRedPoint:(NSNotification *)notificaition {
  1641. NSDictionary *dict = notificaition.userInfo;
  1642. NSString *textJS = [NSString stringWithFormat:@"afterReceivePushMessage('%@','%@')",dict[@"typeMsg"],dict[@"url"]];
  1643. [self isExitCallToJS:textJS withMethodName:@"afterReceivePushMessage"];
  1644. }
  1645. #pragma mark ****粘贴板相关-梳理
  1646. -(void)updateClipboard:(NSNotification *)notificaition{
  1647. NSString *current_url = [self stringByEvaluatingJavaScriptFromString:@"document.location.href"];
  1648. NSDictionary *dict = notificaition.userInfo;
  1649. NSString *content = [NSString stringWithFormat:@"%@",dict[@"content"]];
  1650. if ([current_url containsString:@"jyapp/free/login"]) {
  1651. [GlobalData shareInstance].isPasteLogin = YES;
  1652. }else {
  1653. [self popPasteVIew:content];
  1654. }
  1655. }
  1656. -(void)openTheClipboard:(NSNotification *)notificaition{
  1657. NSLog(@"菜单一打开指定粘贴板url");
  1658. NSDictionary *dict = notificaition.userInfo;
  1659. NSString *tmpUrl = [NSString stringWithFormat:@"%@%@", kHost, dict[@"url"]];
  1660. tmpUrl = [tmpUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  1661. kMainQueue(^{
  1662. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:tmpUrl]]];
  1663. })
  1664. }
  1665. //弹出粘贴板框
  1666. -(void)popPasteVIew:(NSString *)content {
  1667. [[LXNetworkManager shareLXNetworkManager]postWithURLStr:[NSString stringWithFormat:@"%@distribution/share/getWordInfo",kHost] parameters:@{@"copyTxt":content} progress:^(NSProgress *progress) {
  1668. NSLog(@"%@",progress);
  1669. } success:^(id responseObject) {
  1670. NSLog(@"responseObject=%@",responseObject);
  1671. if ([responseObject objectForKey:@"data"]) {
  1672. NSDictionary *dict = [[NSDictionary alloc]initWithDictionary:responseObject[@"data"]];
  1673. if ([dict objectForKey:@"title"]) {
  1674. self.clipboardView.title =dict[@"title"];
  1675. self.clipboardView.subTitle =dict[@"subTitle"];
  1676. self.clipboardView.imgUrl =dict[@"imgUrl"];
  1677. self.clipboardView.appUrl =dict[@"appUrl"];
  1678. self.clipboardView.butTxt =dict[@"butTxt"];
  1679. self.clipboardView.bottomTxt =dict[@"bottomTxt"];
  1680. [self.clipboardView show];
  1681. }
  1682. }
  1683. } failure:^(NSError *error) {
  1684. NSLog(@"error=%@",error);
  1685. }];
  1686. }
  1687. #pragma mark **** 代理方法
  1688. -(void)clipboardClick:(NSString *)url {
  1689. //发送通知打开粘贴板-url
  1690. [[NSNotificationCenter defaultCenter] postNotificationName:OpenTheClipboard object:nil userInfo:@{@"url":url}];
  1691. }
  1692. /*
  1693. #pragma mark - Navigation
  1694. // In a storyboard-based application, you will often want to do a little preparation before navigation
  1695. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  1696. // Get the new view controller using [segue destinationViewController].
  1697. // Pass the selected object to the new view controller.
  1698. }
  1699. */
  1700. @end