|
@@ -1,1601 +0,0 @@
|
|
-//
|
|
|
|
-// JYSearchViewController.m
|
|
|
|
-// JianYuIOS
|
|
|
|
-//
|
|
|
|
-// Created by apple on 2018/11/8.
|
|
|
|
-// Copyright © 2018年 lixianglan. All rights reserved.
|
|
|
|
-//
|
|
|
|
-
|
|
|
|
-#import "JYSearchViewController.h"
|
|
|
|
-#import "JYTabBarController.h"
|
|
|
|
-#import <CoreLocation/CoreLocation.h>
|
|
|
|
-#import <WebKit/WebKit.h>
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-@protocol JYSearchViewControllerJSExport<JSExport>
|
|
|
|
-
|
|
|
|
-JSExportAs(loginByWeixin, -(NSString *)jsLoginByWeixin:(NSString *)str);// 微信登录 openid
|
|
|
|
-JSExportAs(share, -(void)jsShare:(NSString *)type title:(NSString *)title content:(NSString *)content link:(NSString *)link); // 调用分享
|
|
|
|
-JSExportAs(saveUserToken, -(void)jsSaveUserToken:(NSString *)token);// 登录时获取令牌 保存
|
|
|
|
-JSExportAs(getUserToken, -(NSString *)jsGetUserToken:(NSString *)str);// 取本地存的令牌
|
|
|
|
-JSExportAs(removeUserToken, -(void)jsRemoveUserToken:(NSString *)str); // 退出时清空数据
|
|
|
|
-JSExportAs(checkNoticePermission, -(int)jsCheckNoticePermission:(NSString *)str); // 查询手机通知是否打开
|
|
|
|
-JSExportAs(openSystemNotification, -(void)jsOpenSystemNotification:(NSString *)str);// 跳转到系统设置
|
|
|
|
-JSExportAs(getPushRid, -(NSString *)jsGetPushRid:(NSString *)str);// 返回极光id
|
|
|
|
-JSExportAs(getMessageList, -(NSString *)jsGetMessageList:(NSString *)openid);// 按通知接收时间倒排,取前100条
|
|
|
|
-JSExportAs(updateMessageState, -(void)jsUpdateMessageState:(NSString *)lxID state:(NSString *)state);// 更新状态
|
|
|
|
-JSExportAs(deleteMessageById, -(void)jsDeleteMessageById:(NSString *)lxID);// 删除一条消息
|
|
|
|
-JSExportAs(getMessage, -(NSString *)jsGetMessage:(NSString *)lxID);// 取单条数据
|
|
|
|
-JSExportAs(getUnReadMessageCount, -(int)jsGetUnReadMessageCount:(NSString *)openid);// 获取未读消息总数
|
|
|
|
-JSExportAs(updateAllUnReadMessage, -(void)jsUpdateAllUnReadMessage:(NSString *)openid);// 全部置为已读
|
|
|
|
-JSExportAs(lightStatusBar, -(void)jsLightStatusBar:(NSString *)status);// 导航栏文字颜色
|
|
|
|
-JSExportAs(openExternalLink, -(void)jsOpenExternalLink:(NSString *)url title:(NSString *)title);// 打开新控制器 加载新web
|
|
|
|
-JSExportAs(getVersion, -(NSString *)jsGetVersion:(NSString *)str);// 获取当前版本号
|
|
|
|
-JSExportAs(alert, -(void)jsAlert:(NSString *)content);// 弹框
|
|
|
|
-JSExportAs(isInstallWeixin, -(int)jsIsInstallWeixin:(NSString *)str);// 是否安装微信
|
|
|
|
-JSExportAs(changeMessageType, -(void)jsChangeMessageType:(NSString *)link);//已读操作处理
|
|
|
|
-JSExportAs(openActivityPage, -(void)jsOpenActivityPage:(NSString *)url rectype:(NSString *)rectype openid:(NSString *)openid);
|
|
|
|
-JSExportAs(getCipherText, -(NSString *)jsGGetCipherText:(NSString *)phone);
|
|
|
|
-JSExportAs(business, -(NSInteger)jsBusiness:(NSInteger)shooID shopType:(NSInteger )shopType);
|
|
|
|
-//新增
|
|
|
|
-JSExportAs(hiddenBottom, -(void)jsHiddenBottom:(NSString*)hidden);
|
|
|
|
-//刷新其他页面
|
|
|
|
-JSExportAs(checkLab, -(void)jsCheckLab:(NSString*)str);
|
|
|
|
-//登录相关
|
|
|
|
-JSExportAs(loginSuccess, -(void)jsLoginSuccess:(NSString*)status);
|
|
|
|
-JSExportAs(backUrl, -(void)jsBackUrl:(NSString*)str);
|
|
|
|
-//JSExportAs(redirectKeyset, -(void)jsRedirectKeyset:(NSString*)str);
|
|
|
|
-JSExportAs(clearPushMessage, -(void)jsClearPushMessage:(NSString*)type);
|
|
|
|
-JSExportAs(hideRedSpotOnMenu, -(void)jsHideRedSpotOnMenu:(NSString*)str);
|
|
|
|
-JSExportAs(showRedSpotOnMenu, -(void)jsShowRedSpotOnMenu:(NSString*)str);
|
|
|
|
-//支付相关
|
|
|
|
-JSExportAs(wxPay, -(void)jsWxPay:(NSString *)jsonString);
|
|
|
|
-JSExportAs(aliPay, -(void)jsAliPay:(NSString*)str);
|
|
|
|
-//原生通知
|
|
|
|
-JSExportAs(getOtherPushRid, -(NSString *)jsGetOtherPushRid:(NSString *)str);
|
|
|
|
-JSExportAs(getPhoneBrand, -(NSString *)jsGetPhoneBrand:(NSString *)str);
|
|
|
|
-//返回省-市
|
|
|
|
-JSExportAs(getLocation, -(NSString *)jsGetLocation:(NSString *)str);
|
|
|
|
-//切换底部栏
|
|
|
|
-JSExportAs(chooseTab, -(void)jsChooseTab:(int)indexTab);
|
|
|
|
-//拍照上传照片
|
|
|
|
-JSExportAs(skipCamera, -(void)jsSkipCamera:(NSString*)str);
|
|
|
|
-//相册选择照片
|
|
|
|
-JSExportAs(skipAlbum, -(void)jsSkipAlbum:(NSString*)str);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-@end
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-@interface JYSearchViewController ()<UIWebViewDelegate, JYSearchViewControllerJSExport,CLLocationManagerDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate,NJKWebViewProgressDelegate>
|
|
|
|
-{
|
|
|
|
- CGPoint startTouch;
|
|
|
|
- BOOL _isMoving;
|
|
|
|
-
|
|
|
|
- NSInteger pushIndex;//第几个模块过来的
|
|
|
|
-
|
|
|
|
- NSInteger _timeTick;
|
|
|
|
- NSInteger _time;
|
|
|
|
-
|
|
|
|
- BOOL autologin;
|
|
|
|
- BOOL notiFinish;
|
|
|
|
- BOOL refreshTabBool; //实验室-百宝箱 是否刷新
|
|
|
|
- BOOL isLoadRedDot;
|
|
|
|
-
|
|
|
|
- NJKWebViewProgressView *_webViewProgressView;
|
|
|
|
- NJKWebViewProgress *_webViewProgress;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-@property(nonatomic, strong)UIWebView *webView;
|
|
|
|
-
|
|
|
|
-@property (strong, nonatomic) NSURLConnection *connection;
|
|
|
|
-@property (strong, nonatomic) NSURLCache *urlCache;
|
|
|
|
-@property (strong, nonatomic) NSMutableURLRequest *request;
|
|
|
|
-@property (strong, nonatomic) NSURL *url;
|
|
|
|
-
|
|
|
|
-//@property (weak, nonatomic) IBOutlet UIWebView *webView;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-@property(nonatomic, assign)BOOL updateNotify;
|
|
|
|
-@property(nonatomic, assign)BOOL afterOpenPushMessage;
|
|
|
|
-@property(nonatomic, strong)NoNetView *noNetView;
|
|
|
|
-@property(nonatomic, strong)NSURLRequest *errRequest;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-@property (nonatomic, strong)NSMutableDictionary *notiDict;
|
|
|
|
-@property (nonatomic,weak)NSTimer *timer;
|
|
|
|
-
|
|
|
|
-@property(nonatomic,strong)CLLocationManager *locaationManager;
|
|
|
|
-@property(nonatomic,strong)NSString *placeAdr;
|
|
|
|
-@property(nonatomic,assign)BOOL isLocation;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-@property(nonatomic,strong)UIProgressView *progressView;
|
|
|
|
-@end
|
|
|
|
-
|
|
|
|
-NSString *const kInitVector_0 = @"1389461544135476";
|
|
|
|
-size_t const kKeySize_0 = kCCKeySizeAES128;
|
|
|
|
-NSString *const AesKey_0 = @"mGlAgnIBB8bx2nch";
|
|
|
|
-
|
|
|
|
-@implementation JYSearchViewController
|
|
|
|
-
|
|
|
|
--(void)viewWillAppear:(BOOL)animated
|
|
|
|
-{
|
|
|
|
- [super viewWillAppear:animated];
|
|
|
|
- [self.navigationController setNavigationBarHidden:YES animated:animated];
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-- (void)viewDidLoad {
|
|
|
|
- [super viewDidLoad];
|
|
|
|
- NSLog(@"初始化--首页");
|
|
|
|
- //清缓存
|
|
|
|
- self.view.backgroundColor = [UIColor whiteColor];
|
|
|
|
-
|
|
|
|
-// WKWebView *webview = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
|
|
|
|
-// [self.view addSubview:webview];
|
|
|
|
-// NSString *url = [NSString stringWithFormat:@"%@%@", kHost, @"jyapp/free/index"];
|
|
|
|
-// NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
|
|
|
|
-// [webview loadRequest:request];
|
|
|
|
-
|
|
|
|
- if (iPhoneX) {
|
|
|
|
- self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-TAB_BAR_HEIGHT)];
|
|
|
|
- if (@available(iOS 11.0, *)) {
|
|
|
|
- self.webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
|
|
|
- }
|
|
|
|
- }else {
|
|
|
|
- self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, -STATUS_BAR_HEIGHT, WIDTH, HEIGHT-TAB_BAR_HEIGHT+STATUS_BAR_HEIGHT)];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- [self.view addSubview: self.webView];
|
|
|
|
- self.webView.scrollView.bounces = NO;
|
|
|
|
- self.webView.delegate = self;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- _webViewProgress = [[NJKWebViewProgress alloc] init];
|
|
|
|
- _webView.delegate = _webViewProgress;
|
|
|
|
- _webViewProgress.webViewProxyDelegate = self;
|
|
|
|
- _webViewProgress.progressDelegate = self;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-// CGRect navBounds = self.navigationController.navigationBar.bounds;
|
|
|
|
-// CGRect barFrame = CGRectMake(0,navBounds.size.height - 2,navBounds.size.width,2);
|
|
|
|
-
|
|
|
|
- CGRect barFrame = CGRectMake(0,STATUS_BAR_HEIGHT - 2,WIDTH,2);
|
|
|
|
- _webViewProgressView = [[NJKWebViewProgressView alloc] initWithFrame:barFrame];
|
|
|
|
- _webViewProgressView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
|
|
|
|
- [_webViewProgressView setProgress:0 animated:YES];
|
|
|
|
-
|
|
|
|
- [self.view addSubview:_webViewProgressView];
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- [[LXViewControllerManager shareViewControllerManager] showHudText:nil];
|
|
|
|
- [self webViewFirstRequest];//请求页面数据
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(requestWebView:) name:kRequestWebViewWithUrl object:nil];
|
|
|
|
- //点击订阅通知
|
|
|
|
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clickSubNotiMethods:) name:ClickSubNotiMethods object:nil];
|
|
|
|
- //点击支付通知
|
|
|
|
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clickPayMethods:) name:ClickPayMethods object:nil];
|
|
|
|
- //支付状态通知
|
|
|
|
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(alipayWXpayStatus:) name:AlipayWXpayStatus object:nil];
|
|
|
|
-
|
|
|
|
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateNotifyState) name:kUpdateNotifyState object:nil];
|
|
|
|
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(afterReceiveNewMsg) name:kAfterReceiveNewMsg object:nil];
|
|
|
|
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadWebView) name:kReloadWebVIew object:nil];
|
|
|
|
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginOut:) name:kLoginOut object:nil];
|
|
|
|
-
|
|
|
|
- [[AFNetworkReachabilityManager sharedManager] startMonitoring];
|
|
|
|
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netReachChanged:) name:AFNetworkingReachabilityDidChangeNotification object:nil];
|
|
|
|
-
|
|
|
|
- UIPanGestureRecognizer *recognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(paningGestureReceive:)];
|
|
|
|
- [recognizer delaysTouchesBegan];
|
|
|
|
- [self.view addGestureRecognizer:recognizer];
|
|
|
|
- //手势
|
|
|
|
-
|
|
|
|
- //新增监听
|
|
|
|
-
|
|
|
|
- if([LXUserDefaults isExistToken]) {
|
|
|
|
- self.notiDict = [[NSMutableDictionary alloc]initWithDictionary:[[NSUserDefaults standardUserDefaults] objectForKey:RemoteNotifications]];
|
|
|
|
- if(self.notiDict.count) {
|
|
|
|
- self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeFireMethod) userInfo:nil repeats:YES];
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- //前往登录通知-tabbar
|
|
|
|
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(isLoginTabBar:) name:LoginIndexTabBar object:nil];
|
|
|
|
- //展示底部红的通知
|
|
|
|
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(newsRedPoint:) name:JYNewsRedPoint object:nil];
|
|
|
|
- //接收全新通知
|
|
|
|
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshNonCurVC:) name:RefreshNonCurVC object:nil];
|
|
|
|
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshAllVC:) name:RefreshAllVC object:nil];
|
|
|
|
-
|
|
|
|
- //初始化临时属性
|
|
|
|
- self.placeAdr = [NSString new];
|
|
|
|
-
|
|
|
|
- //清缓存
|
|
|
|
-// [self clearWeb];
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-//进度条
|
|
|
|
-#pragma mark - NJKWebViewProgressDelegate
|
|
|
|
--(void)webViewProgress:(NJKWebViewProgress *)webViewProgress updateProgress:(float)progress
|
|
|
|
-{
|
|
|
|
- [_webViewProgressView setProgress:progress animated:YES];
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
--(void)newsRedPoint:(NSNotification *)notificaition
|
|
|
|
-{
|
|
|
|
- NSDictionary *dict = notificaition.userInfo;
|
|
|
|
- NSLog(@"%@",dict);
|
|
|
|
- NSInteger type = [dict[@"type"] integerValue];
|
|
|
|
- if(type==1) {
|
|
|
|
- //显示
|
|
|
|
- kMainQueue(^{
|
|
|
|
- [self.tabBarController.tabBar showBadgeOnItemIndex:1];
|
|
|
|
- });
|
|
|
|
- }else if (type==2) {
|
|
|
|
- //显示
|
|
|
|
- kMainQueue(^{
|
|
|
|
- [self.tabBarController.tabBar showBadgeOnItemIndex:3];
|
|
|
|
- });
|
|
|
|
- }else {
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if(self.tabBarController.selectedIndex == 0) {
|
|
|
|
-
|
|
|
|
- NSString *textJS = [NSString stringWithFormat:@"afterReceivePushMessage('%@','%@')",dict[@"typeMsg"],dict[@"url"]];
|
|
|
|
- NSLog(@"%@",textJS);
|
|
|
|
- JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
|
|
|
|
- [context evaluateScript:textJS];
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
--(void)haveRedPoint
|
|
|
|
-{
|
|
|
|
- NSLog(@"http请求-------小红点");
|
|
|
|
- NSString *token = [LXUserDefaults token];
|
|
|
|
- if ([LXUserDefaults isExistToken]) {
|
|
|
|
- [[LXNetworkManager shareLXNetworkManager]postWithURLStr:[NSString stringWithFormat:@"%@jyapp/free/showRedSpotOnMenu",kHost] parameters:@{@"token":token} progress:^(NSProgress *progress) {
|
|
|
|
- NSLog(@"%@",progress);
|
|
|
|
- } success:^(id responseObject) {
|
|
|
|
- NSLog(@"responseObject=%@",responseObject);
|
|
|
|
-
|
|
|
|
- if([responseObject[@"subscribe"] integerValue]>=1) {
|
|
|
|
- //显示
|
|
|
|
- [GlobalData shareInstance].subIsRed = YES;
|
|
|
|
- kMainQueue(^{
|
|
|
|
- [self.tabBarController.tabBar showBadgeOnItemIndex:1];
|
|
|
|
- });
|
|
|
|
- }else {
|
|
|
|
- [GlobalData shareInstance].subIsRed = NO;
|
|
|
|
- kMainQueue(^{
|
|
|
|
- [self.tabBarController.tabBar hideBadgeOnItemIndex:1];
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if([responseObject[@"my"] integerValue]>=1) {
|
|
|
|
- //显示
|
|
|
|
- [GlobalData shareInstance].mineIsRed = YES;
|
|
|
|
- kMainQueue(^{
|
|
|
|
- [self.tabBarController.tabBar showBadgeOnItemIndex:3];
|
|
|
|
- });
|
|
|
|
- }else {
|
|
|
|
- [GlobalData shareInstance].mineIsRed = NO;
|
|
|
|
- kMainQueue(^{
|
|
|
|
- [self.tabBarController.tabBar hideBadgeOnItemIndex:3];
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- } failure:^(NSError *error) {
|
|
|
|
- NSLog(@"error=%@",error);
|
|
|
|
- }];
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-//2.5.1
|
|
|
|
--(void)timeFireMethod{
|
|
|
|
- _timeTick++;
|
|
|
|
- NSLog(@"定时器");
|
|
|
|
- if(self.webView&¬iFinish) {
|
|
|
|
- NSString * urlStr = [NSString stringWithFormat:@"%@",self.notiDict[@"info"][@"url"]];
|
|
|
|
-
|
|
|
|
- if (urlStr) {
|
|
|
|
- if([self.notiDict[@"type"] isEqualToString:@"bid"]) {
|
|
|
|
- AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
|
|
|
|
- JYTabBarController *tab = (JYTabBarController *)delegate.window.rootViewController;
|
|
|
|
- tab.selectedIndex = 1;
|
|
|
|
- [self performSelector:@selector(pushDY:) withObject:self.notiDict[@"info"] afterDelay:1];
|
|
|
|
-
|
|
|
|
- }else {
|
|
|
|
- [[LXViewControllerManager shareViewControllerManager] showHudText:nil];
|
|
|
|
- self.afterOpenPushMessage = YES;
|
|
|
|
- [self performSelector:@selector(requestWebTime:) withObject:self.notiDict afterDelay:1];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- [self.timer invalidate];
|
|
|
|
- self.timer = nil;
|
|
|
|
- _timeTick = 0;
|
|
|
|
- [[NSUserDefaults standardUserDefaults] removeObjectForKey:RemoteNotifications];
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (_timeTick == 60) {
|
|
|
|
- [self.timer invalidate];
|
|
|
|
- self.timer = nil;
|
|
|
|
- _timeTick = 0;
|
|
|
|
- [[NSUserDefaults standardUserDefaults] removeObjectForKey:RemoteNotifications];
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
--(void)moveViewWithX:(float)x
|
|
|
|
-{
|
|
|
|
- CGRect rect = self.view.bounds;
|
|
|
|
- CGFloat width = CGRectGetWidth(rect);
|
|
|
|
- x = x>width?width:x;
|
|
|
|
- x = x<0?0:x;
|
|
|
|
- CGRect frame = self.webView.frame;
|
|
|
|
- frame.origin.x = x;
|
|
|
|
- self.webView.frame = frame;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-#pragma mark – Gesture Recognizer –
|
|
|
|
--(void)paningGestureReceive:(UIPanGestureRecognizer *)recoginzer
|
|
|
|
-{
|
|
|
|
- NSString *current_url = [self.webView stringByEvaluatingJavaScriptFromString:@"document.location.href"];
|
|
|
|
- NSLog(@"当前页面:%@",current_url);
|
|
|
|
- CGRect rect = self.view.bounds;
|
|
|
|
- CGFloat width = CGRectGetWidth(rect);
|
|
|
|
- if (![self.webView canGoBack]) {
|
|
|
|
- NSLog(@"不可返回");
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- if([current_url containsString:@"jyapp/free/login"]) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // NSString *current_url = self.webView.request.URL.absoluteString;
|
|
|
|
- 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]]){
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //https://www.jianyu360.com/jyapp/free/me
|
|
|
|
- //https://www.jianyu360.com/jyapp/jylab/index
|
|
|
|
- //https://www.jianyu360.com/jyapp/wxkeyset/keyset/index
|
|
|
|
- //https://www.jianyu360.com/jyapp/jylab/mainSearch
|
|
|
|
-
|
|
|
|
- CGPoint touchPoint = [recoginzer locationInView:[UIApplication sharedApplication].keyWindow];
|
|
|
|
- if (recoginzer.state==UIGestureRecognizerStateBegan) {
|
|
|
|
- _isMoving = YES;
|
|
|
|
- startTouch = touchPoint;
|
|
|
|
- } else if (recoginzer.state==UIGestureRecognizerStateEnded){
|
|
|
|
- if (touchPoint.x - startTouch.x > width*0.125) {
|
|
|
|
- [UIView animateWithDuration:0.3 animations:^{
|
|
|
|
- [self moveViewWithX:width];
|
|
|
|
- JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
|
|
|
|
- [context evaluateScript:@"afterClickBack()"];
|
|
|
|
- [self.webView goBack];
|
|
|
|
- } completion:^(BOOL finished) {
|
|
|
|
- _isMoving = NO;
|
|
|
|
- [self moveViewWithX:0];
|
|
|
|
- }];
|
|
|
|
- } else {
|
|
|
|
- [UIView animateWithDuration:0.3 animations:^{
|
|
|
|
- [self moveViewWithX:0];
|
|
|
|
- } completion:^(BOOL finished) {
|
|
|
|
- _isMoving = NO;
|
|
|
|
- }];
|
|
|
|
- }
|
|
|
|
- return;
|
|
|
|
- } else if (recoginzer.state==UIGestureRecognizerStateCancelled){
|
|
|
|
- [UIView animateWithDuration:0.3 animations:^{
|
|
|
|
- [self moveViewWithX:0];
|
|
|
|
- } completion:^(BOOL finished) {
|
|
|
|
- _isMoving = NO;
|
|
|
|
- }];
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- if (_isMoving) {
|
|
|
|
- [self moveViewWithX:touchPoint.x - startTouch.x];
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-// 监控网络状态变化
|
|
|
|
--(void)netReachChanged:(NSNotification *)notificaition{
|
|
|
|
- NSDictionary *userInfo = notificaition.userInfo;
|
|
|
|
- if ([userInfo[@"AFNetworkingReachabilityNotificationStatusItem"] intValue] == 0 || [userInfo[@"AFNetworkingReachabilityNotificationStatusItem"] intValue] == -1) {
|
|
|
|
- [self addNoNetViews];
|
|
|
|
- }else{
|
|
|
|
- [self removeNoNetViews];
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// 再次加载页面
|
|
|
|
--(void)reloadWebView{
|
|
|
|
- [[LXViewControllerManager shareViewControllerManager] showHudText:nil];
|
|
|
|
- if (!self.webView.canGoBack) {
|
|
|
|
- [self webViewFirstRequest];
|
|
|
|
- }else{
|
|
|
|
- [self.webView reload];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// 首次加载web
|
|
|
|
--(void)webViewFirstRequest{
|
|
|
|
- NSString *url = [NSString stringWithFormat:@"%@%@", kHost, @"jyapp/free/index"];
|
|
|
|
- NSString *token = [LXUserDefaults token];
|
|
|
|
- if ([LXUserDefaults isExistToken]) {
|
|
|
|
- url = [url stringByAppendingString:[NSString stringWithFormat:@"?sign=%@&url=/jyapp/jylab/mainSearch&from=restart", token]];
|
|
|
|
- }
|
|
|
|
- NSLog(@"111第一次加载%@",url);
|
|
|
|
- url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
|
|
|
|
-
|
|
|
|
- kMainQueue(^{
|
|
|
|
- [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-//收到消息退出并重新加载web
|
|
|
|
--(void)webViewRequestByMsg{
|
|
|
|
-
|
|
|
|
- NSString *url = [NSString stringWithFormat:@"%@%@", kHost, @"jyapp/free/login?back=index&isios=t&flag=kicked"];
|
|
|
|
-
|
|
|
|
- url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
|
|
|
|
- [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
--(void)requestWebTime:(NSDictionary *)infoDict
|
|
|
|
-{
|
|
|
|
- NSString * urlStr = [NSString stringWithFormat:@"%@",infoDict[@"info"][@"url"]];
|
|
|
|
-
|
|
|
|
- if([infoDict[@"type"] isEqualToString:@"message"]) {
|
|
|
|
- NSString *url = [NSString stringWithFormat:@"%@",urlStr];
|
|
|
|
- NSArray * array = [url componentsSeparatedByString:@"=="];
|
|
|
|
- url = [array.firstObject stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
|
|
|
|
- [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
|
|
|
|
- [[NSNotificationCenter defaultCenter] postNotificationName:@"kNewWebControllerDismiss" object:nil];
|
|
|
|
-
|
|
|
|
- }else if ([infoDict[@"type"] isEqualToString:@"titleMessage"]) {
|
|
|
|
- //新增支付 后台唤起
|
|
|
|
-
|
|
|
|
- NSArray * array = [urlStr componentsSeparatedByString:@"=="];
|
|
|
|
- urlStr = [array.firstObject stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
|
|
|
|
- NSString * titleStr = @"消息通知";
|
|
|
|
- titleStr = [NSString stringWithFormat:@"%@",infoDict[@"info"][@"title"]];
|
|
|
|
- if (urlStr) {
|
|
|
|
- if(self.tabBarController.selectedIndex == 0) {
|
|
|
|
- [self jsOpenExternalLink:urlStr title:titleStr];
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }else {
|
|
|
|
- NSString *url = [NSString stringWithFormat:@"%@%@", kHost, urlStr];
|
|
|
|
- url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
|
|
|
|
- [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
|
|
|
|
- [[NSNotificationCenter defaultCenter] postNotificationName:@"kNewWebControllerDismiss" object:nil];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// 点击通知 跳转到通知内url
|
|
|
|
--(void)requestWebView:(NSNotification *)notification{
|
|
|
|
- NSDictionary * infoDict = [notification object];
|
|
|
|
- if (!infoDict) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- NSString * urlStr = [NSString stringWithFormat:@"%@",infoDict[@"info"][@"url"]];
|
|
|
|
-
|
|
|
|
- if (urlStr) {
|
|
|
|
- //当前控制器
|
|
|
|
- if(self.tabBarController.selectedIndex != 0) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- [[LXViewControllerManager shareViewControllerManager] showHudText:nil];
|
|
|
|
- self.afterOpenPushMessage = YES;
|
|
|
|
- [self performSelector:@selector(requestWebTime:) withObject:infoDict afterDelay:1];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
--(void)clickSubNotiMethods:(NSNotification *)notification{
|
|
|
|
- NSDictionary * infoDict = [notification object][@"info"];
|
|
|
|
- if (!infoDict) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- NSLog(@"%@",infoDict);
|
|
|
|
- NSString * urlStr = [NSString stringWithFormat:@"%@",infoDict[@"url"]];
|
|
|
|
- if (urlStr) {
|
|
|
|
- NSLog(@"有info");
|
|
|
|
- if(self.tabBarController.selectedIndex == 0) {
|
|
|
|
- //底部栏置换到订阅
|
|
|
|
- AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
|
|
|
|
- JYTabBarController *tab = (JYTabBarController *)delegate.window.rootViewController;
|
|
|
|
- tab.selectedIndex = 1;
|
|
|
|
-
|
|
|
|
- [self performSelector:@selector(pushDY:) withObject:infoDict afterDelay:1];
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-//点击支付通知
|
|
|
|
--(void)clickPayMethods:(NSNotification *)notification{
|
|
|
|
- NSDictionary * infoDict = [notification object][@"info"];
|
|
|
|
- if (!infoDict) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- NSString * urlStr = [NSString stringWithFormat:@"%@",infoDict[@"url"]];
|
|
|
|
- NSArray * array = [urlStr componentsSeparatedByString:@"=="];
|
|
|
|
- urlStr = [array.firstObject stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
|
|
|
|
- NSString * titleStr = @"消息通知";
|
|
|
|
- titleStr = [NSString stringWithFormat:@"%@",infoDict[@"title"]];
|
|
|
|
- if (urlStr) {
|
|
|
|
- if(self.tabBarController.selectedIndex == 0) {
|
|
|
|
- [self jsOpenExternalLink:urlStr title:titleStr];
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
--(void)pushDY:(NSDictionary *)infoDict
|
|
|
|
-{
|
|
|
|
- [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshDY" object:nil userInfo:infoDict];
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-#pragma mark 收到z支付通知
|
|
|
|
--(void)alipayWXpayStatus:(NSNotification *)notification{
|
|
|
|
-
|
|
|
|
- NSString * status = [notification object];
|
|
|
|
- [self performSelector:@selector(payStatus:) withObject:status afterDelay:2];
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
--(void)payStatus:(NSString *)status
|
|
|
|
-{
|
|
|
|
- //目前延时两秒
|
|
|
|
- NSLog(@"支付状态:%@",status);
|
|
|
|
-
|
|
|
|
- if(self.tabBarController.selectedIndex == 0) {
|
|
|
|
- JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
|
|
|
|
- NSString * textJS1 = [NSString stringWithFormat:@"payCallBack('%@')", status];
|
|
|
|
- [context evaluateScript:textJS1];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-// 收到通知消息
|
|
|
|
--(void)afterReceiveNewMsg{
|
|
|
|
- NSLog(@"afterReceiveNewMsg");
|
|
|
|
- JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
|
|
|
|
- [context evaluateScript:@"afterReceiveNewMsg()"];
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// 收到退出登录消息
|
|
|
|
--(void)loginOut:(NSNotification *)notification{
|
|
|
|
- if([notification.userInfo[@"item_index"] integerValue]!=0) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- [self webViewRequestByMsg];
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-//刷新页面相关
|
|
|
|
--(void)refreshNonCurVC:(NSNotification *)notificaition{
|
|
|
|
- if(self.tabBarController.selectedIndex != 0) {
|
|
|
|
- refreshTabBool = YES;
|
|
|
|
- [self webViewFirstRequest];
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
--(void)refreshAllVC:(NSNotification *)notificaition{
|
|
|
|
- [self webViewFirstRequest];
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-//前往登录页面
|
|
|
|
--(void)isLoginTabBar:(NSNotification *)notification
|
|
|
|
-{
|
|
|
|
- NSDictionary *dict = notification.userInfo;
|
|
|
|
- NSLog(@"我从第几个页面过来:%@",dict[@"item_index"]);
|
|
|
|
- pushIndex = [dict[@"item_index"] integerValue];
|
|
|
|
- NSString *url = [NSString stringWithFormat:@"%@%@", kHost, @"jyapp/free/login"];
|
|
|
|
- url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
|
|
|
|
- [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-//js返回首页
|
|
|
|
--(void)jsBackUrl:(NSString*)str
|
|
|
|
-{
|
|
|
|
- NSLog(@"search返回首页,search返回首页");
|
|
|
|
- if([str isEqualToString:@"H"]) {
|
|
|
|
- pushIndex = 0;
|
|
|
|
- [self webViewFirstRequest];
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-//js方法登录成功
|
|
|
|
--(void)jsLoginSuccess:(NSString*)status
|
|
|
|
-{
|
|
|
|
- NSLog(@"首页登录成功提示");
|
|
|
|
- [GlobalData shareInstance].isReLogin = YES;
|
|
|
|
- if([status isEqualToString:@"S"]) {
|
|
|
|
- if(pushIndex!=0) {
|
|
|
|
- kMainQueue((^{
|
|
|
|
- [[NSNotificationCenter defaultCenter] postNotificationName:RefreshAllVC object:nil userInfo:nil];
|
|
|
|
- AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
|
|
|
|
- JYTabBarController *tab = (JYTabBarController *)delegate.window.rootViewController;
|
|
|
|
- tab.selectedIndex = pushIndex;
|
|
|
|
- pushIndex = 0;
|
|
|
|
- }));
|
|
|
|
- }else {
|
|
|
|
- NSLog(@"刷新页面------当前页面");
|
|
|
|
- [self webViewFirstRequest];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }else if ([status isEqualToString:@""]) {
|
|
|
|
- //不刷新订阅-首页,刷新其他
|
|
|
|
- [[NSNotificationCenter defaultCenter] postNotificationName:RefreshExpAndMine object:nil userInfo:nil];
|
|
|
|
- }else {
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-- (void)hideTabBar {
|
|
|
|
- NSLog(@"隐藏tabbar");
|
|
|
|
- kMainQueue(^{
|
|
|
|
- if (self.tabBarController.tabBar.hidden == YES) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- UIView *contentView;
|
|
|
|
- if ( [[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] )
|
|
|
|
- contentView = [self.tabBarController.view.subviews objectAtIndex:1];
|
|
|
|
- else
|
|
|
|
- contentView = [self.tabBarController.view.subviews objectAtIndex:0];
|
|
|
|
- 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);
|
|
|
|
- self.tabBarController.tabBar.hidden = YES;
|
|
|
|
- });
|
|
|
|
-}
|
|
|
|
-- (void)showTabBar{
|
|
|
|
- kMainQueue(^{
|
|
|
|
- if (self.tabBarController.tabBar.hidden == NO)
|
|
|
|
- {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- UIView *contentView;
|
|
|
|
- if ([[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]])
|
|
|
|
-
|
|
|
|
- contentView = [self.tabBarController.view.subviews objectAtIndex:1];
|
|
|
|
-
|
|
|
|
- else
|
|
|
|
-
|
|
|
|
- contentView = [self.tabBarController.view.subviews objectAtIndex:0];
|
|
|
|
- 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);
|
|
|
|
- self.tabBarController.tabBar.hidden = NO;
|
|
|
|
- });
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
--(void)judgeIsHidden
|
|
|
|
-{
|
|
|
|
- NSString *current_url = [self.webView stringByEvaluatingJavaScriptFromString:@"document.location.href"];
|
|
|
|
-
|
|
|
|
- //[current_url isEqualToString:[NSString stringWithFormat:@"%@jyapp/free/index",kHost]]
|
|
|
|
- // NSLog(@"%@",current_url);
|
|
|
|
- if([current_url isEqualToString:[NSString stringWithFormat:@"%@jyapp/jylab/mainSearch",kHost]]){
|
|
|
|
- NSLog(@"展示");
|
|
|
|
- [self showTabBar];
|
|
|
|
- [self showMethodTabBar];
|
|
|
|
- }else {
|
|
|
|
- NSLog(@"隐藏");
|
|
|
|
- [self hideTabBar];
|
|
|
|
- [self hiddenMethodTabBar];
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
--(void)jsHiddenBottom:(NSString *)hidden
|
|
|
|
-{
|
|
|
|
- NSLog(@"让我展示隐藏bottom==%@",hidden);
|
|
|
|
- if(self.tabBarController.selectedIndex == 0) {
|
|
|
|
- if([hidden integerValue]==0) {
|
|
|
|
- [self hideTabBar];
|
|
|
|
- [self hiddenMethodTabBar];
|
|
|
|
-
|
|
|
|
- }else {
|
|
|
|
- [self showTabBar];
|
|
|
|
- [self showMethodTabBar];
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
--(void)hiddenMethodTabBar
|
|
|
|
-{
|
|
|
|
- kMainQueue(^{
|
|
|
|
- if (iPhoneX) {
|
|
|
|
- if (@available(iOS 11.0, *)) {
|
|
|
|
- self.webView.frame = CGRectMake(0, 0, WIDTH, HEIGHT);
|
|
|
|
- NSLog(@"%@",self.webView)
|
|
|
|
- }
|
|
|
|
- }else {
|
|
|
|
- self.webView.frame = CGRectMake(0, -STATUS_BAR_HEIGHT, WIDTH, HEIGHT+STATUS_BAR_HEIGHT);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
-}
|
|
|
|
--(void)showMethodTabBar
|
|
|
|
-{
|
|
|
|
- kMainQueue(^{
|
|
|
|
- if (iPhoneX) {
|
|
|
|
- if (@available(iOS 11.0, *)) {
|
|
|
|
- self.webView.frame = CGRectMake(0, 0, WIDTH, HEIGHT-TAB_BAR_HEIGHT);
|
|
|
|
- }
|
|
|
|
- }else {
|
|
|
|
- self.webView.frame = CGRectMake(0, -STATUS_BAR_HEIGHT, WIDTH, HEIGHT-TAB_BAR_HEIGHT+STATUS_BAR_HEIGHT);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-#pragma mark webView代理方法
|
|
|
|
-- (void)webViewDidFinishLoad:(UIWebView *)webView{
|
|
|
|
-
|
|
|
|
- NSLog(@"加载完成:%@",[self.webView stringByEvaluatingJavaScriptFromString:@"document.location.href"]);
|
|
|
|
-
|
|
|
|
- //第一次加载小红点
|
|
|
|
- if(!isLoadRedDot) {
|
|
|
|
- isLoadRedDot = true;
|
|
|
|
- [self haveRedPoint];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if(!notiFinish) {
|
|
|
|
- notiFinish = YES;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if(refreshTabBool){
|
|
|
|
- refreshTabBool = NO;
|
|
|
|
- }else {
|
|
|
|
- //正常的网页加载
|
|
|
|
- [self judgeIsHidden];//是否隐藏
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- [self removeNoNetViews];
|
|
|
|
- [[LXViewControllerManager shareViewControllerManager] hideHud];
|
|
|
|
- JSContext *context = [webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
|
|
|
|
- // // Disable user selection
|
|
|
|
- [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitUserSelect='none';"];
|
|
|
|
- // Disable callout
|
|
|
|
- [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitTouchCallout='none';"];
|
|
|
|
-
|
|
|
|
- context[@"JyObj"] = self;
|
|
|
|
-
|
|
|
|
- [context evaluateScript:@"afterPageInit()"];
|
|
|
|
-
|
|
|
|
- if (self.afterOpenPushMessage) {
|
|
|
|
- self.afterOpenPushMessage = NO;
|
|
|
|
- // [context evaluateScript:@"afterOpenPushMessage()"];
|
|
|
|
- [context evaluateScript:[NSString stringWithFormat:@"afterOpenPushMessage('%d')", [self jsIsCanBack:nil]]];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-#pragma mark ****拦截.doc相关链接****
|
|
|
|
-- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
|
|
|
|
-{
|
|
|
|
- //判断是否是单击
|
|
|
|
- if (navigationType == UIWebViewNavigationTypeLinkClicked){
|
|
|
|
- //当前页面
|
|
|
|
-// /jyapp/article/content/
|
|
|
|
- NSString *curWebUrl =[self.webView stringByEvaluatingJavaScriptFromString:@"document.location.href"];
|
|
|
|
- NSLog(@"当前页面:%@",curWebUrl);
|
|
|
|
- if ([curWebUrl containsString:@"jyapp/article/content"]) {
|
|
|
|
- NSString *url = [request.URL absoluteString];
|
|
|
|
- NSLog(@"拦截的页面:%@",url);
|
|
|
|
- //拦截链接跳转到货源圈的动态详情
|
|
|
|
- if (![url containsString:kHost]) {
|
|
|
|
- NewWebController *ctr = [[NewWebController alloc] init];
|
|
|
|
- ctr.url = url;
|
|
|
|
- ctr.titleShow = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
|
|
|
|
- kMainQueue(^{
|
|
|
|
- [self presentViewController:ctr animated:NO completion:nil];
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- return NO;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return YES;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
--(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
|
|
|
|
- [[LXViewControllerManager shareViewControllerManager] hideHud];
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
--(void)webViewDidStartLoad:(UIWebView *)webView{
|
|
|
|
- // if ([[UIDevice currentDevice].systemVersion floatValue] < 10) {
|
|
|
|
- // [[LXViewControllerMager shareViewControllerManager] hideHud];
|
|
|
|
- // }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-- (void)didReceiveMemoryWarning {
|
|
|
|
- [super didReceiveMemoryWarning];
|
|
|
|
- // Dispose of any resources that can be recreated.
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
--(void)clearWeb{
|
|
|
|
- NSURLCache * cache = [NSURLCache sharedURLCache];
|
|
|
|
- [cache removeAllCachedResponses];
|
|
|
|
- [cache setDiskCapacity:0];
|
|
|
|
- [cache setMemoryCapacity:0];
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
--(void)addNoNetViews{
|
|
|
|
- kMainQueue(^{
|
|
|
|
- [self removeNoNetViews];
|
|
|
|
- self.noNetView = [NoNetView shareView];
|
|
|
|
- [self.view addSubview:self.noNetView];
|
|
|
|
- });
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
--(void)removeNoNetViews{
|
|
|
|
- if (self.noNetView ) {
|
|
|
|
- [self.noNetView removeFromSuperview];
|
|
|
|
- self.noNetView = nil;
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-#pragma mark JS 回调
|
|
|
|
-// 微信登录
|
|
|
|
--(NSString *)jsLoginByWeixin:(NSString *)str{
|
|
|
|
-
|
|
|
|
- if ([LXUserDefaults isInstallWeiXin] != 1) { // 没有安装微信 不走友盟
|
|
|
|
- [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"微信登录失败,没有安装微信" delay:1.5];
|
|
|
|
- return nil;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- kMainQueue(^{
|
|
|
|
-
|
|
|
|
- [[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_WechatSession currentViewController:self completion:^(id result, NSError *error) {
|
|
|
|
-
|
|
|
|
- UMSocialUserInfoResponse *resp = result;
|
|
|
|
-
|
|
|
|
- [self dealWXDic:(NSDictionary *)resp.originalResponse];
|
|
|
|
-
|
|
|
|
- [[LXViewControllerManager shareViewControllerManager] hideHud];
|
|
|
|
- }];
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- return nil;
|
|
|
|
-}
|
|
|
|
-// 处理微信登录获取到的数据
|
|
|
|
--(void)dealWXDic:(NSDictionary *)dictionary{
|
|
|
|
-
|
|
|
|
- [[LXViewControllerManager shareViewControllerManager] showHudText:nil];
|
|
|
|
- //如果获取到用户信息,即用户点击了“登录”,则进行用户信息获取
|
|
|
|
- if (dictionary.count > 0) {
|
|
|
|
-
|
|
|
|
- NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:dictionary];
|
|
|
|
-
|
|
|
|
- if (dic) {
|
|
|
|
- [dic removeObjectForKey:@"privilege"];
|
|
|
|
- [dic removeObjectForKey:@"language"];
|
|
|
|
- double currDouble = [[NSDate date] timeIntervalSince1970];
|
|
|
|
- [dic setObject:[NSNumber numberWithLong:(long)currDouble] forKey:@"createtime"];
|
|
|
|
-
|
|
|
|
- // 拼接标志位
|
|
|
|
- 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"]];
|
|
|
|
- sign = [LXMD5 md532BitLower:sign];
|
|
|
|
- [dic setObject:sign forKey:@"sign"];
|
|
|
|
- NSString *endStr = [[LXViewControllerManager shareViewControllerManager] getJsonStr:dic];
|
|
|
|
- NSData *data = [endStr dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
- endStr = [data base64EncodedStringWithOptions:0];
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
|
|
|
|
- NSString * textJS1 = [NSString stringWithFormat:@"loginByWeixinCallBack('%@')", endStr];
|
|
|
|
- JSValue *value = [context evaluateScript:textJS1];
|
|
|
|
- NSLog(@"%@", value);
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// js 调用分享
|
|
|
|
--(void)jsShare:(NSString *)type title:(NSString *)title content:(NSString *)content link:(NSString *)link{
|
|
|
|
- UMSocialPlatformType shareType;
|
|
|
|
-
|
|
|
|
- if ([type intValue] == 1) { // 微信好友
|
|
|
|
- shareType = UMSocialPlatformType_WechatSession;
|
|
|
|
- }else if ([type intValue] == 2){ /// qq好友
|
|
|
|
- shareType = UMSocialPlatformType_QQ;
|
|
|
|
- }else if ([type intValue] == 3){ // 朋友圈
|
|
|
|
- shareType = UMSocialPlatformType_WechatTimeLine;
|
|
|
|
- }else{
|
|
|
|
- shareType = UMSocialPlatformType_WechatSession;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- kMainQueue((^{
|
|
|
|
-
|
|
|
|
- // 没有安装app 不走分享逻辑
|
|
|
|
- if ([type intValue] == 1 || [type intValue] == 3) {
|
|
|
|
- if ([LXUserDefaults isInstallWeiXin] != 1) {
|
|
|
|
- [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"没有安装微信" delay:1.5];
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- // 没有安装app 不走分享逻辑
|
|
|
|
- if ([type intValue] == 2) {
|
|
|
|
- if (![[UMSocialManager defaultManager] isInstall:UMSocialPlatformType_QQ]) {
|
|
|
|
- [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"没有安装QQ" delay:1.5];
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //创建分享消息对象
|
|
|
|
- UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
|
|
|
|
- //创建网页内容对象
|
|
|
|
- UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:title descr:content thumImage:[UIImage imageNamed:@"logo"]];
|
|
|
|
- //设置网页地址
|
|
|
|
- shareObject.webpageUrl = link;
|
|
|
|
- messageObject.shareObject = shareObject;
|
|
|
|
- //调用分享接口
|
|
|
|
- [[UMSocialManager defaultManager] shareToPlatform:shareType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
|
|
|
|
- if (error) {
|
|
|
|
- NSLog(@"22222222%@",error.userInfo);
|
|
|
|
- if (error.userInfo[@"message"] && [error.userInfo[@"message"] containsString:@"Operation is cancel"]) {
|
|
|
|
- [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"取消分享" delay:1];
|
|
|
|
- }else{
|
|
|
|
- [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:error.userInfo[@"message"] delay:1];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- NSString *textJS = [NSString stringWithFormat:@"shareCallBack('%@','%@')",type,@"0"];
|
|
|
|
- JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
|
|
|
|
- [context evaluateScript:textJS];
|
|
|
|
-
|
|
|
|
- }else{
|
|
|
|
- if ([data isKindOfClass:[UMSocialShareResponse class]]) {
|
|
|
|
- UMSocialShareResponse *resp = data;
|
|
|
|
- NSLog(@"33333%@",resp.message);
|
|
|
|
- NSLog(@"44444%@",resp.originalResponse);
|
|
|
|
-
|
|
|
|
- NSString *textJS = [NSString stringWithFormat:@"shareCallBack('%@','%@')",type,@"1"];
|
|
|
|
- JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
|
|
|
|
- [context evaluateScript:textJS];
|
|
|
|
-
|
|
|
|
- }else{
|
|
|
|
- UMSocialLogInfo(@"response data is %@",data);
|
|
|
|
- NSLog(@"55555%@",data);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }];
|
|
|
|
- }));
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// 登录时获取到令牌 并保存
|
|
|
|
--(void)jsSaveUserToken:(NSString *)token{
|
|
|
|
- NSLog(@"登陆成功");
|
|
|
|
- [[LXViewControllerManager shareViewControllerManager] hideHud];
|
|
|
|
- [LXUserDefaults saveToken:token];
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// 取本地的用户令牌
|
|
|
|
--(NSString *)jsGetUserToken:(NSString *)str{
|
|
|
|
- NSLog(@"取用户token");
|
|
|
|
- return [LXUserDefaults token];
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// 退出时 清空用户数据
|
|
|
|
--(void)jsRemoveUserToken:(NSString *)str{
|
|
|
|
- NSLog(@"清除用户token");
|
|
|
|
- [LXUserDefaults clearAll];
|
|
|
|
- // [[LXDataBaseManager shareDataBaseManager] clearAll];
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-// 手机通知权限是否打开
|
|
|
|
--(int)jsCheckNoticePermission:(NSString *)str{
|
|
|
|
- int a = [LXUserDefaults notifyState];
|
|
|
|
- return a;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// 跳转到系统设置
|
|
|
|
--(void)jsOpenSystemNotification:(NSString *)str{
|
|
|
|
- self.updateNotify = YES;
|
|
|
|
- kMainQueue(^{
|
|
|
|
- [[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
|
|
|
|
- });
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// 调用js方法 刷新推送权限状态
|
|
|
|
--(void)updateNotifyState{
|
|
|
|
- if (self.updateNotify) {
|
|
|
|
- self.updateNotify = NO;
|
|
|
|
- JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
|
|
|
|
- NSString * textJS1 = [NSString stringWithFormat:@"updateNoticeSwitch()"];
|
|
|
|
- [context evaluateScript:textJS1];
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-// 获取推送id
|
|
|
|
--(NSString *)jsGetPushRid:(NSString *)str{
|
|
|
|
- return [LXUserDefaults registrationID];
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// 按通知取数据
|
|
|
|
--(NSString *)jsGetMessageList:(NSString *)openid{
|
|
|
|
- NSArray *arr = [[LXDataBaseManager shareDataBaseManager] getMessageWithKey:nil openid:openid fromTable:kNewsTable start:0 length:100];
|
|
|
|
- if (arr.count > 0) {
|
|
|
|
- return [[LXViewControllerManager shareViewControllerManager] getJsonStr:arr];
|
|
|
|
- }
|
|
|
|
- return @"";
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// 更新消息状态
|
|
|
|
--(void)jsUpdateMessageState:(NSNumber *)lxID state:(NSNumber *)state{
|
|
|
|
- [[LXDataBaseManager shareDataBaseManager] changeReadedWithID:lxID state:state];
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// 删除一条数据
|
|
|
|
--(void)jsDeleteMessageById:(NSNumber *)lxID{
|
|
|
|
- [[LXDataBaseManager shareDataBaseManager] deleteMessage:lxID fromTable:kNewsTable];
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// 取单条数据
|
|
|
|
--(NSString *)jsGetMessage:(NSString *)lxID{
|
|
|
|
- return [[LXViewControllerManager shareViewControllerManager] getJsonStr:[[LXDataBaseManager shareDataBaseManager] getMessageWithKey:lxID openid:nil fromTable:kNewsTable start:0 length:0]];
|
|
|
|
-}
|
|
|
|
-// 取未读消息总数
|
|
|
|
--(int)jsGetUnReadMessageCount:(NSString *)openid{
|
|
|
|
- NSLog(@"openid=%@",openid);
|
|
|
|
- // NSLog(@"%d",[[LXDataBaseManager shareDataBaseManager] getUnReadMessageCount:openid]);
|
|
|
|
- // if([[LXDataBaseManager shareDataBaseManager] getUnReadMessageCount:openid] ==0){
|
|
|
|
- // //显示
|
|
|
|
- // kMainQueue(^{
|
|
|
|
- // [self.tabBarController.tabBar hideBadgeOnItemIndex:3];
|
|
|
|
- // });
|
|
|
|
- // }else {
|
|
|
|
- // kMainQueue(^{
|
|
|
|
- // [self.tabBarController.tabBar showBadgeOnItemIndex:3];
|
|
|
|
- // });
|
|
|
|
- // }
|
|
|
|
- return [[LXDataBaseManager shareDataBaseManager] getUnReadMessageCount:openid];
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// 全部置为已读
|
|
|
|
--(void)jsUpdateAllUnReadMessage:(NSString *)openid{
|
|
|
|
- [[LXDataBaseManager shareDataBaseManager] updateAllUnReadMessage:openid];
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// 改变状态栏文字颜色
|
|
|
|
--(void)jsLightStatusBar:(NSString *)status{
|
|
|
|
- kMainQueue(^{
|
|
|
|
- NSInteger index = 0;
|
|
|
|
- if ([status intValue] == 1) {
|
|
|
|
- index = 1;// hei
|
|
|
|
- }else{
|
|
|
|
- index = 0;// bai
|
|
|
|
- }
|
|
|
|
- [[UIApplication sharedApplication] setStatusBarStyle:index];
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-// 打开新页面 加载新web
|
|
|
|
--(void)jsOpenExternalLink:(NSString *)url title:(NSString *)title{
|
|
|
|
- if (url) {
|
|
|
|
- if ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable || [AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusUnknown) {
|
|
|
|
- // [self addNoNetViews];
|
|
|
|
- }
|
|
|
|
- NewWebController *ctr = [[NewWebController alloc] init];
|
|
|
|
- ctr.url = url;
|
|
|
|
- // 有title的话 会显示自定义的导航栏 没有的话不显示导航栏 显示加载进度条
|
|
|
|
- if (!title || [title isEqualToString:@""] || [title isEqualToString:@"undefined"]) {
|
|
|
|
- ctr.titleShow = nil;
|
|
|
|
- }else{
|
|
|
|
- ctr.titleShow = title;
|
|
|
|
- }
|
|
|
|
- kMainQueue(^{
|
|
|
|
- [self presentViewController:ctr animated:NO completion:nil];
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// 获取当前版本号
|
|
|
|
--(NSString *)jsGetVersion:(NSString *)str{
|
|
|
|
- return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// web是否可退回上页面
|
|
|
|
--(int)jsIsCanBack:(NSString *)str{
|
|
|
|
- return self.webView.canGoBack ? 1:0;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// 弹框
|
|
|
|
--(void)jsAlert:(NSString *)content{
|
|
|
|
- [[LXViewControllerManager shareViewControllerManager] showAlertViewWithMessage:content];
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// 是否安装微信
|
|
|
|
--(int)jsIsInstallWeixin:(NSString *)str{
|
|
|
|
- return [LXUserDefaults isInstallWeiXin];
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
--(void)jsChangeMessageType:(NSString *)link
|
|
|
|
-{
|
|
|
|
- //已读操作处理
|
|
|
|
- NSLog(@"已读操作处理-更改");
|
|
|
|
- [[LXDataBaseManager shareDataBaseManager] changeCatagoryTypeWithURL:link];
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
--(void)jsOpenActivityPage:(NSString *)url rectype:(NSString *)rectype openid:(NSString *)openid
|
|
|
|
-{
|
|
|
|
- NSDictionary * infoDic = @{@"url":url,
|
|
|
|
- @"rectype":rectype,
|
|
|
|
- @"openid":openid,
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- // NSString *textJS = [NSString stringWithFormat:@"messageAccept('%@','%@','%@')",infoDic[@"mid"],infoDic[@"rectype"],infoDic[@"openid"]];
|
|
|
|
- // JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
|
|
|
|
- // [context evaluateScript:textJS];
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- //post请求
|
|
|
|
- NSLog(@"%@",[NSString stringWithFormat:@"%@jyapp/free/message/receive",kHost]);
|
|
|
|
- [[LXNetworkManager shareLXNetworkManager]postWithURLStr:[NSString stringWithFormat:@"%@jyapp/free/message/receive",kHost] parameters:infoDic progress:^(NSProgress *progress) {
|
|
|
|
- NSLog(@"成功:%@",progress);
|
|
|
|
- } success:^(id responseObject) {
|
|
|
|
- NSLog(@"responseObject=%@",responseObject);
|
|
|
|
- } failure:^(NSError *error) {
|
|
|
|
- NSLog(@"error=%@",error);
|
|
|
|
- }];
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
--(NSString *)jsGGetCipherText:(NSString *)phone
|
|
|
|
-{
|
|
|
|
-
|
|
|
|
- NSDate *date=[NSDate date];
|
|
|
|
- NSDateFormatter *format1=[[NSDateFormatter alloc] init];
|
|
|
|
- [format1 setDateFormat:@"yyyyMMddhhmmss"];
|
|
|
|
- NSString *dateStr;
|
|
|
|
- dateStr=[format1 stringFromDate:date];
|
|
|
|
- NSLog(@"%@",dateStr);
|
|
|
|
-
|
|
|
|
- NSString *content = [[NSString stringWithFormat:@"%@_%@",phone,dateStr] stringByAppendingString:[NSString stringWithFormat:@"_%@",[LXMD5 md532BitLower:[NSString stringWithFormat:@"%@&%@",phone,dateStr]]]];
|
|
|
|
- NSData *contentData = [content dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
- NSUInteger dataLength = contentData.length;
|
|
|
|
- // 为结束符'\\0' +1
|
|
|
|
- char keyPtr[kKeySize_0 + 1];
|
|
|
|
- memset(keyPtr, 0, sizeof(keyPtr));
|
|
|
|
- [AesKey_0 getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
|
|
|
|
- // 密文长度 <= 明文长度 + BlockSize
|
|
|
|
- size_t encryptSize = dataLength + kCCBlockSizeAES128;
|
|
|
|
- void *encryptedBytes = malloc(encryptSize);
|
|
|
|
- size_t actualOutSize = 0;
|
|
|
|
- NSData *initVector = [kInitVector_0 dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
- CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt,
|
|
|
|
- kCCAlgorithmAES,
|
|
|
|
- kCCOptionPKCS7Padding, // 系统默认使用 CBC,然后指明使用 PKCS7Padding
|
|
|
|
- keyPtr,
|
|
|
|
- kKeySize_0,
|
|
|
|
- initVector.bytes,
|
|
|
|
- contentData.bytes,
|
|
|
|
- dataLength,
|
|
|
|
- encryptedBytes,
|
|
|
|
- encryptSize,
|
|
|
|
- &actualOutSize);
|
|
|
|
- if (cryptStatus == kCCSuccess) {
|
|
|
|
- // 对加密后的数据进行 base64 编码
|
|
|
|
- return [[NSData dataWithBytesNoCopy:encryptedBytes length:actualOutSize] base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
|
|
|
|
- }
|
|
|
|
- free(encryptedBytes);
|
|
|
|
- return nil;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
--(void)jsHideRedSpotOnMenu:(NSString*)str
|
|
|
|
-{
|
|
|
|
- NSLog(@"search隐藏:%@",str);
|
|
|
|
- if([str isEqualToString:@"subscribe"]) {
|
|
|
|
- kMainQueue(^{
|
|
|
|
- [self.tabBarController.tabBar hideBadgeOnItemIndex:1];
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- if([str isEqualToString:@"my"]) {
|
|
|
|
- kMainQueue(^{
|
|
|
|
- [self.tabBarController.tabBar hideBadgeOnItemIndex:3];
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
--(void)jsShowRedSpotOnMenu:(NSString*)str
|
|
|
|
-{
|
|
|
|
- NSLog(@"search展示:%@",str);
|
|
|
|
- if([str isEqualToString:@"subscribe"]) {
|
|
|
|
- kMainQueue(^{
|
|
|
|
- [self.tabBarController.tabBar showBadgeOnItemIndex:1];
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- if([str isEqualToString:@"my"]) {
|
|
|
|
- kMainQueue(^{
|
|
|
|
- [self.tabBarController.tabBar showBadgeOnItemIndex:3];
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
--(void)jsClearPushMessage:(NSString*)type
|
|
|
|
-{
|
|
|
|
- NSLog(@"清除通知栏");
|
|
|
|
- kMainQueue(^{
|
|
|
|
- [[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
|
|
|
|
- [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
|
|
|
|
- });
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-#pragma mark 支付相关
|
|
|
|
-
|
|
|
|
--(void)jsWxPay:(NSString *)jsonString
|
|
|
|
-{
|
|
|
|
- if ([LXUserDefaults isInstallWeiXin] != 1) { // 没有安装wx
|
|
|
|
- [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"请先安装微信再进行支付!" delay:1.5];
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
- NSError *err;
|
|
|
|
- NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
|
|
|
|
- if(err) {
|
|
|
|
- NSLog(@"json解析失败:%@",err);
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- //吊起微信
|
|
|
|
- PayReq *request = [[PayReq alloc] init] ;
|
|
|
|
- request.openID = dic[@"Appid"];
|
|
|
|
- request.partnerId = dic[@"Partnerid"];
|
|
|
|
- request.prepayId= dic[@"Prepayid"];
|
|
|
|
- request.package = @"Sign=WXPay";
|
|
|
|
- request.nonceStr= dic[@"Noncestr"];
|
|
|
|
- request.timeStamp= [dic[@"Timestamp"] intValue];
|
|
|
|
- request.sign= dic[@"Sign"];
|
|
|
|
-
|
|
|
|
- kMainQueue(^{
|
|
|
|
- [WXApi sendReq:request];
|
|
|
|
- });
|
|
|
|
-}
|
|
|
|
--(void)jsAliPay:(NSString*)str
|
|
|
|
-{
|
|
|
|
- kMainQueue(^{
|
|
|
|
- [[AlipaySDK defaultService] payOrder:str fromScheme:@"jianyuiosapp" callback:nil];
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-#pragma mark 原生通知相关
|
|
|
|
--(NSString *)jsGetOtherPushRid:(NSString *)str
|
|
|
|
-{
|
|
|
|
- NSLog(@"取deviceToken:%@",[LXUserDefaults deviceToken]);
|
|
|
|
- return [LXUserDefaults deviceToken];
|
|
|
|
-}
|
|
|
|
--(NSString *)jsGetPhoneBrand:(NSString *)str
|
|
|
|
-{
|
|
|
|
- UIDevice *device = [UIDevice currentDevice];
|
|
|
|
- return device.platformString;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
--(void)jsChooseTab:(int)indexTab
|
|
|
|
-{
|
|
|
|
- kMainQueue((^{
|
|
|
|
- AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
|
|
|
|
- JYTabBarController *tab = (JYTabBarController *)delegate.window.rootViewController;
|
|
|
|
- tab.selectedIndex = indexTab;
|
|
|
|
- pushIndex = indexTab;
|
|
|
|
- }));
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-//刷新页面方法
|
|
|
|
--(void)jsCheckLab:(NSString*)str
|
|
|
|
-{
|
|
|
|
- [[NSNotificationCenter defaultCenter] postNotificationName:RefreshNonCurVC object:nil userInfo:nil];
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-//获取定位相关
|
|
|
|
--(NSString *)jsGetLocation:(NSString *)str
|
|
|
|
-{
|
|
|
|
- NSLog(@"------开始调用获取位置");
|
|
|
|
- if (!self.isLocation) {
|
|
|
|
- // 1.检查定位服务是否开启
|
|
|
|
- if ([self checkLocationServiceIsEnabled]) {
|
|
|
|
- // 2.创建定位管理器:
|
|
|
|
- [self createCLManager];
|
|
|
|
- self.isLocation = YES; //只请求一次
|
|
|
|
- }else{
|
|
|
|
- NSLog(@"定位不可用");
|
|
|
|
- self.isLocation = NO;
|
|
|
|
- }
|
|
|
|
- NSLog(@"即将返回城市信息-%@",self.placeAdr);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return self.placeAdr;
|
|
|
|
-}
|
|
|
|
-- (BOOL)checkLocationServiceIsEnabled{
|
|
|
|
- // 该方法是类方法,和我们创建的管理器没有关系
|
|
|
|
- if ([CLLocationManager locationServicesEnabled]) {
|
|
|
|
- return YES;
|
|
|
|
- }
|
|
|
|
- return NO;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-- (void)createCLManager{
|
|
|
|
- // 创建CoreLocation管理对象
|
|
|
|
- self.locaationManager = [[CLLocationManager alloc]init];
|
|
|
|
- // 设定定位精准度
|
|
|
|
- [self.locaationManager setDesiredAccuracy:kCLLocationAccuracyBest];
|
|
|
|
- // 设定DistanceFilter可以在用户移动指定距离之后触发更新事件(100米更新一次)
|
|
|
|
- [self.locaationManager setDistanceFilter:100.f];
|
|
|
|
- // 设置代理
|
|
|
|
- self.locaationManager.delegate = self;
|
|
|
|
- // 开始更新定位
|
|
|
|
- [self.locaationManager startUpdatingLocation];
|
|
|
|
-}
|
|
|
|
-// 代理方法,更新位置
|
|
|
|
-- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations{
|
|
|
|
- CLLocation * newLocation = [locations lastObject];
|
|
|
|
- // 判空处理
|
|
|
|
- if (newLocation.horizontalAccuracy < 0) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- CLGeocoder *geocoder = [[CLGeocoder alloc] init];
|
|
|
|
- [geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
|
|
|
|
- for (CLPlacemark *placeMark in placemarks) {
|
|
|
|
- //NSLog(@"位置:%@", placeMark.name);
|
|
|
|
- //NSLog(@"街道:%@", placeMark.thoroughfare);
|
|
|
|
- //NSLog(@"子街道:%@", placeMark.subThoroughfare);
|
|
|
|
- //NSLog(@"区\\县:%@", placeMark.subLocality);
|
|
|
|
- //NSLog(@"市:%@", placeMark.locality);
|
|
|
|
- //NSLog(@"行政区:%@", placeMark.administrativeArea);
|
|
|
|
- //NSLog(@"国家:%@", placeMark.country);
|
|
|
|
-
|
|
|
|
- self.placeAdr = [placeMark.administrativeArea stringByAppendingString:[NSString stringWithFormat:@"-%@",placeMark.locality]];
|
|
|
|
- }
|
|
|
|
- }];
|
|
|
|
-
|
|
|
|
- // [self.locaationManager stopUpdatingLocation];
|
|
|
|
- // self.locaationManager.delegate=nil;
|
|
|
|
- // //获取定位经纬度
|
|
|
|
- // CLLocationCoordinate2D coor2D = newLocation.coordinate;
|
|
|
|
- // NSLog(@"纬度为:%f, 经度为:%f", coor2D.latitude, coor2D.longitude);
|
|
|
|
- //
|
|
|
|
- // // 获取定位海拔高度
|
|
|
|
- // CLLocationDistance altitude = newLocation.altitude;
|
|
|
|
- // NSLog(@"高度为:%f", altitude);
|
|
|
|
- //
|
|
|
|
- // // 获取定位水平精确度, 垂直精确度
|
|
|
|
- // CLLocationAccuracy horizontalAcc = newLocation.horizontalAccuracy;
|
|
|
|
- // CLLocationAccuracy verticalAcc = newLocation.verticalAccuracy;
|
|
|
|
- // NSLog(@"%f, %f", horizontalAcc, verticalAcc);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// 代理方法,定位权限检查
|
|
|
|
--(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{
|
|
|
|
- switch (status) {
|
|
|
|
- case kCLAuthorizationStatusNotDetermined:{
|
|
|
|
- NSLog(@"用户还未决定授权");
|
|
|
|
- // 主动获得授权
|
|
|
|
- [self.locaationManager requestWhenInUseAuthorization];
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- case kCLAuthorizationStatusRestricted:
|
|
|
|
- {
|
|
|
|
- NSLog(@"访问受限");
|
|
|
|
- // 主动获得授权
|
|
|
|
- [self.locaationManager requestWhenInUseAuthorization];
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- case kCLAuthorizationStatusDenied:{
|
|
|
|
- // 此时使用主动获取方法也不能申请定位权限
|
|
|
|
- // 类方法,判断是否开启定位服务
|
|
|
|
- if ([CLLocationManager locationServicesEnabled]) {
|
|
|
|
- NSLog(@"定位服务开启,被拒绝");
|
|
|
|
- } else {
|
|
|
|
- NSLog(@"定位服务关闭,不可用");
|
|
|
|
- }
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- case kCLAuthorizationStatusAuthorizedAlways:{
|
|
|
|
- NSLog(@"获得前后台授权");
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- case kCLAuthorizationStatusAuthorizedWhenInUse:{
|
|
|
|
- NSLog(@"获得前台授权");
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- default:
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-//拍照上传图片
|
|
|
|
--(void)jsSkipCamera:(NSString*)str{
|
|
|
|
-
|
|
|
|
- UIImagePickerController *picker = [[UIImagePickerController alloc] init];
|
|
|
|
- picker.delegate = self;
|
|
|
|
- picker.allowsEditing = YES;
|
|
|
|
- picker.sourceType = UIImagePickerControllerSourceTypeCamera;
|
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
- [self presentViewController:picker animated:YES completion:nil];
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-//相册选择照片
|
|
|
|
--(void)jsSkipAlbum:(NSString*)str{
|
|
|
|
-
|
|
|
|
- UIImagePickerController *picker = [[UIImagePickerController alloc] init];
|
|
|
|
- picker.delegate = self;
|
|
|
|
- picker.allowsEditing = YES;
|
|
|
|
- picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
|
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
- [self presentViewController:picker animated:YES completion:nil];
|
|
|
|
- });
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-//获取到图片
|
|
|
|
-- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
|
|
|
|
-{
|
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
- [picker dismissViewControllerAnimated:YES completion:^{
|
|
|
|
- UIImage * img=[info objectForKey:UIImagePickerControllerEditedImage];
|
|
|
|
- NSData *data = UIImageJPEGRepresentation(img, 0.5);
|
|
|
|
- if (data!=nil) {
|
|
|
|
- [self uploadPic:data];
|
|
|
|
- }else{
|
|
|
|
- NSLog(@"data == nil");
|
|
|
|
- [self uploadUrl:@""];
|
|
|
|
- }
|
|
|
|
- }];
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-//取消获取照片
|
|
|
|
-- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
|
|
|
|
-{
|
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
- [picker dismissViewControllerAnimated:YES completion:^{
|
|
|
|
- [self uploadUrl:@""];
|
|
|
|
- }];
|
|
|
|
- });
|
|
|
|
-}
|
|
|
|
-//上传图片
|
|
|
|
--(void)uploadPic:(NSData *)data
|
|
|
|
-{
|
|
|
|
- NSDictionary * body = @{@"type":@"courseFile"};
|
|
|
|
- AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
|
|
|
|
- //ContentType设置
|
|
|
|
- manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html",@"image/jpeg",@"image/png",@"application/octet-stream",@"text/json",@"text/plain",nil];
|
|
|
|
- manager.responseSerializer= [AFHTTPResponseSerializer serializer];
|
|
|
|
- manager.requestSerializer = [AFHTTPRequestSerializer serializer];
|
|
|
|
- manager.requestSerializer.timeoutInterval = 15.0f;
|
|
|
|
- [manager POST:[NSString stringWithFormat:@"%@filemanage/upload",kHost] parameters:body constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
|
|
|
|
- //上传的参数(上传图片,以文件流的格式)
|
|
|
|
- [formData appendPartWithFileData:data
|
|
|
|
- name:@"courseFile"
|
|
|
|
- fileName:@"courseFile.jpeg"
|
|
|
|
- mimeType:@"image/jpeg"];
|
|
|
|
- } progress:^(NSProgress * _Nonnull uploadProgress) {
|
|
|
|
-
|
|
|
|
- CGFloat progress = 100.0 * uploadProgress.completedUnitCount / uploadProgress.totalUnitCount;
|
|
|
|
- NSLog(@"%.2lf%%", progress);
|
|
|
|
- } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
|
|
|
- //请求成功的block回调
|
|
|
|
-
|
|
|
|
- NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
|
|
|
|
- NSLog(@"上传成功%@",dic);
|
|
|
|
-
|
|
|
|
- if ([dic[@"msg"] isEqualToString:@"ssss"]) {
|
|
|
|
- [self uploadUrl:dic[@"url"]];
|
|
|
|
- }else{
|
|
|
|
- [self uploadUrl:@""];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
|
|
|
-
|
|
|
|
- NSLog(@"上传失败%@",error);
|
|
|
|
- [self uploadUrl:@""];
|
|
|
|
-
|
|
|
|
- }];
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
--(void)uploadUrl:(NSString *)url
|
|
|
|
-{
|
|
|
|
- NSString *textJS = [[NSString alloc]init];
|
|
|
|
- if ([url isEqualToString:@""]) {
|
|
|
|
- textJS = @"hiddenLoading()";
|
|
|
|
- }else{
|
|
|
|
- textJS = [NSString stringWithFormat:@"uploadImg('%@')",url];
|
|
|
|
- }
|
|
|
|
- if ([url isEqualToString:@""]||[textJS isEqualToString:@""]) {
|
|
|
|
- NSLog(@"空的情况");
|
|
|
|
- textJS = @"hiddenLoading()";
|
|
|
|
- }
|
|
|
|
- [self performSelector:@selector(uploadJS:) withObject:textJS afterDelay:1];
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
--(void)uploadJS:(NSString *)textJS
|
|
|
|
-{
|
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
- [self.webView stringByEvaluatingJavaScriptFromString:textJS];
|
|
|
|
- });
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-/*
|
|
|
|
- #pragma mark - Navigation
|
|
|
|
-
|
|
|
|
- // In a storyboard-based application, you will often want to do a little preparation before navigation
|
|
|
|
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
|
|
|
- // Get the new view controller using [segue destinationViewController].
|
|
|
|
- // Pass the selected object to the new view controller.
|
|
|
|
- }
|
|
|
|
- */
|
|
|
|
-
|
|
|
|
-@end
|
|
|
|
-
|
|
|