//
|
// GeneralWebController.m
|
// MIduo
|
//
|
// Created by 重庆迈尖科技有限公司 on 2019/9/28.
|
// Copyright © 2019 yeshi. All rights reserved.
|
//
|
|
#import "ShonpingShareViewController.h"
|
#import "SureWebViewController.h"
|
#import "SearchDetailMainController.h"
|
#import "InvitationFriendsViewController.h"
|
#import "NoCouponNoRebateController.h"
|
|
#import <WebKit/WebKit.h>
|
#import <sys/utsname.h>
|
#import <AdSupport/AdSupport.h>
|
#import "CZBInfoManager.h"
|
|
#import "SAMKeychain.h"
|
#import <ShareSDK/ShareSDK.h>
|
#import <ShareSDKUI/ShareSDK+SSUI.h>
|
#import "GTMBase64.h"
|
|
#import "SJDynamicShareView.h"
|
#import "WebMorePopView.h"
|
|
#import "HZPhotoBrowser.h"
|
|
@interface ShonpingShareViewController () <WKNavigationDelegate, WKUIDelegate, WKScriptMessageHandler, NewLoginViewDelegate>
|
|
@property (nonatomic, strong) UIButton *closeButton;
|
@property (nonatomic, strong) UIButton *moreShareButton;
|
|
/// 导航栏的下的灰线
|
@property (nonatomic, strong) UIView *navGaryLine;
|
@property (nonatomic, strong) WKWebView *webView;
|
@property (nonatomic, strong) UIProgressView *progressView;
|
|
@property (nonatomic, strong) SJDynamicShareView *shareAppView;
|
@property (nonatomic, nullable, strong) WebMorePopView *webMorePopView;
|
|
@property (nonatomic, strong) NSMutableDictionary *shareDictionary;
|
|
@property (nonatomic, nullable, strong) NSMutableArray *dataMutArr;
|
@property (nonatomic, nullable, strong) NSMutableArray *newAddmMutArr;
|
@property (nonatomic, nullable, strong) NSArray *gudingArr;
|
|
@property (nonatomic, strong) NSMutableArray *tempOldArr;
|
|
@property (nonatomic, strong) NSDictionary *shareDatasource;
|
/// 分享链接
|
@property (nonatomic, nullable, copy) NSString *urlShare;
|
/// 分享名字
|
@property (nonatomic, nullable, copy) NSString *urlName;
|
|
@property (nonatomic, assign) BOOL goodsDetail; //:true是否需要拦截商品详情
|
|
@property (nonatomic, assign) BOOL isBaichuan;
|
/// 网页是否加载完成
|
@property (nonatomic, assign) BOOL isWebViewLoad;
|
|
@property (nonatomic, nullable, strong) NSMutableArray *arrayShareImage;
|
/// 是否下载多张图片
|
@property (nonatomic, assign) BOOL isDownMoreImg;
|
@end
|
|
@implementation ShonpingShareViewController
|
|
- (void)viewDidLoad {
|
[super viewDidLoad];
|
[self setupDataConfig];
|
[self setupNave];
|
[self setupView];
|
[self webViewloadURLType];
|
}
|
|
- (void)viewWillAppear:(BOOL)animated {
|
[super viewWillAppear:animated];
|
|
[self.navigationController setNavigationBarHidden:NO animated:animated];
|
|
[self.webView addObserver:self forKeyPath:@"title" options:NSKeyValueObservingOptionNew context:NULL];
|
[self.webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
|
// addScriptMessageHandler 很容易导致循环引用
|
// 控制器 强引用了WKWebView,WKWebView copy(强引用了)configuration, configuration copy (强引用了)userContentController
|
// userContentController 强引用了 self (控制器)
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"toast"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"jumpGoodsSplash"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"jumpGoodsSplashWithFrom"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"jumpGoodsDetail"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"jumpKeFu"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"jumpBaiChuan"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"jumpPage"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"jumpPageWithFinishCurrentPage"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"umEventCount"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"umEventCompute"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"hiddenTopMenuCloseBtn"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"showSharePanel"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"addMenu"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"copyText"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"jumpSearch"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"jumpInvite"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"login"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"setTitle"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"showLoading"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"hideLoading"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"finishPage"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"jumpJDGoodsDetailWithFrom"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"jumpPDDGoodsDetailWithFrom"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"shareLink"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"shareImg"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"savePicture"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"jumpJD"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"tbAuth"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"shareText"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"clearClipboard"];
|
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"jumpWXXCX"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"shareWXXCX"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"shareImgs"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"savePictures"];
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"showimgs"];
|
|
if (_isWebViewLoad) {
|
NSString *jsFounction = @"yestvcallback.resume()";
|
[self.webView evaluateJavaScript:jsFounction completionHandler:^(id object, NSError * _Nullable error) {
|
//NSLog(@"obj:%@---error:%@", object, error);
|
}];
|
}
|
}
|
|
- (void)viewWillDisappear:(BOOL)animated {
|
[super viewWillDisappear:animated];
|
|
[self.webView removeObserver:self forKeyPath:@"title"];
|
[self.webView removeObserver:self forKeyPath:@"estimatedProgress"];
|
// 因此这里要记得移除handlers
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"toast"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"jumpGoodsSplash"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"jumpGoodsSplashWithFrom"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"jumpGoodsDetail"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"jumpKeFu"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"jumpBaiChuan"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"jumpPage"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"jumpPageWithFinishCurrentPage"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"umEventCount"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"umEventCompute"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"hiddenTopMenuCloseBtn"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"showSharePanel"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"addMenu"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"copyText"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"jumpSearch"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"jumpInvite"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"login"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"setTitle"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"showLoading"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"hideLoading"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"finishPage"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"jumpJDGoodsDetailWithFrom"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"jumpPDDGoodsDetailWithFrom"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"shareLink"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"shareImg"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"savePicture"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"jumpJD"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"tbAuth"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"shareText"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"clearClipboard"];
|
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"jumpWXXCX"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"shareWXXCX"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"shareImgs"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"savePictures"];
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"showimgs"];
|
}
|
|
- (void)setupNave {
|
UIButton *backbutton = [UIButton buttonWithType:UIButtonTypeCustom];
|
backbutton.frame = CGRectMake(0, 0, 32, 30);
|
[backbutton setImage:[UIImage imageNamed:@"all_back"] forState:UIControlStateNormal];
|
[backbutton setTitle:@" " forState:UIControlStateNormal];
|
[backbutton addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
|
UIBarButtonItem *backItem = [[UIBarButtonItem alloc]initWithCustomView:backbutton];
|
|
self.closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
self.closeButton.frame = CGRectMake(0, 0, 32, 30);
|
[self.closeButton setTitle:@" " forState:UIControlStateNormal];
|
[self.closeButton setImage:[UIImage imageNamed:@"new_cancel"] forState:UIControlStateNormal];
|
[self.closeButton addTarget:self action:@selector(closeItem:) forControlEvents:UIControlEventTouchUpInside];
|
UIBarButtonItem *closeItem = [[UIBarButtonItem alloc] initWithCustomView:self.closeButton];
|
|
self.navigationItem.leftBarButtonItems = @[backItem,closeItem];
|
|
self.moreShareButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
self.moreShareButton.frame = CGRectMake(0, 0, 30, 30);
|
[self.moreShareButton setImage:[UIImage imageNamed:@"更多___up"] forState:UIControlStateNormal];
|
[self.moreShareButton addTarget:self action:@selector(shareTaped:) forControlEvents:UIControlEventTouchUpInside];
|
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:self.moreShareButton];
|
|
self.navigationController.navigationBar.translucent = NO;
|
self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:FLQNewNavigationTitleColor, NSFontAttributeName:[UIFont boldSystemFontOfSize:FLQNewNavigationTitleFont]};
|
self.navigationController.navigationBar.barTintColor = FLQNewNavigationBarColor;
|
|
self.view.backgroundColor = XYRBackgroundColor;
|
}
|
|
- (void)setupDataConfig {
|
self.automaticallyAdjustsScrollViewInsets = NO;
|
self.isWebViewLoad = NO;
|
self.clipboard = YES;
|
|
self.shareDictionary = @{}.mutableCopy;
|
if (self.dataDictionary[@"paramsJSON"][@"url"]) {
|
NSString * cleanString = self.dataDictionary[@"paramsJSON"][@"url"];
|
self.urlString = cleanString;
|
|
} else if (self.dataDictionary[@"url"]) {
|
NSString * cleanString = self.dataDictionary[@"url"];
|
self.urlString = cleanString;
|
}
|
|
if (self.dataDictionary[@"paramsJSON"]) {
|
BOOL clipboard = [self.dataDictionary[@"paramsJSON"][@"clipboard"] boolValue];
|
self.clipboard = clipboard;
|
[YTHsharedManger startManger].clipboard = clipboard;
|
|
} else if (self.dataDictionary) {
|
BOOL clipboard = [self.dataDictionary[@"clipboard"] boolValue];
|
self.clipboard = clipboard;
|
[YTHsharedManger startManger].clipboard = clipboard;
|
}
|
|
if (self.dataDictionary[@"paramsJSON"][@"title"]) {
|
NSString * cleanString = self.dataDictionary[@"paramsJSON"][@"title"];
|
self.navaTitle = cleanString;
|
|
} else if (self.dataDictionary[@"title"]) {
|
NSString * cleanString = self.dataDictionary[@"title"];
|
self.navaTitle = cleanString;
|
}
|
// 去掉空格和换行
|
self.urlString = [self removeSpaceAndNewline:_urlString];
|
//监听UIWindow显示
|
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(beginFullScreen) name:UIWindowDidBecomeVisibleNotification object:nil];
|
//监听UIWindow隐藏
|
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(windowDidBecomeHidden:) name:UIWindowDidBecomeHiddenNotification object:nil];
|
}
|
|
- (void)beginFullScreen {
|
|
}
|
|
- (void)windowDidBecomeHidden:(NSNotification *)noti {
|
UIWindow *win = (UIWindow *)noti.object;
|
if (win) {
|
UIViewController *rootVC = win.rootViewController;
|
NSArray<__kindof UIViewController *> *vcs = rootVC.childViewControllers;
|
if([vcs.firstObject isKindOfClass:NSClassFromString(@"AVPlayerViewController")]){
|
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
|
}
|
}
|
}
|
|
- (void)webViewloadURLType {
|
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
|
if (self.urlString) {
|
[params setObject:self.urlString forKey:@"url"];
|
}
|
@weakify(self)
|
[JYNetWorking Post:[NSString stringWithFormat:@"%@/%@",domainHTTP2,@"config/getWebConfig"] param:params success:^(NSDictionary *object)
|
{
|
@strongify(self)
|
@weakify(self)
|
dispatch_async(dispatch_get_main_queue(), ^{
|
@strongify(self)
|
if ([object[@"code"] integerValue] == 0) {
|
self.isBaichuan = [object[@"data"][@"baichuan"] boolValue];
|
self.goodsDetail = [object[@"data"][@"goodsDetail"] boolValue];
|
if (self.isBaichuan) {
|
[self loadALiBaiChuan];
|
|
} else {
|
[self initLoadWebView];
|
}
|
|
} else {
|
[self initLoadWebView];
|
}
|
});
|
|
} fail:^(id object) {
|
@strongify(self)
|
[self initLoadWebView];
|
}];
|
}
|
|
- (void)loadALiBaiChuan {
|
[self.albcServiceManager pushOpenByUrl:self.urlString identity:nil webView:_webView parentController:self.navigationController taoKeParams:nil];
|
}
|
|
- (void)setupView {
|
[self.view addSubview:self.navGaryLine];
|
WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
|
WKPreferences *preferences = [WKPreferences new];
|
preferences.javaScriptCanOpenWindowsAutomatically = YES;
|
configuration.preferences = preferences;
|
|
self.webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - kNavigationBarH - kStatusBarH) configuration:configuration];
|
self.webView.backgroundColor = XYRBackgroundColor;
|
self.webView.navigationDelegate = self;
|
self.webView.UIDelegate = self;
|
|
[self.view addSubview:self.webView];
|
|
[self initProgressView];
|
}
|
|
- (void)initLoadWebView {
|
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.urlString]];
|
[CZBInfoManager setUserAgent:@"blksIOS" webView:self.webView completion:^{
|
[self.webView loadRequest:request];
|
|
}];
|
[CZBInfoManager registerWebView:self.webView];
|
|
|
}
|
|
- (void)initProgressView {
|
CGFloat kScreenWidth = [[UIScreen mainScreen] bounds].size.width;
|
UIProgressView *progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 1)];
|
progressView.tintColor = XYRMainColor;
|
progressView.trackTintColor = UICOLOR_FROM_RGB(0xe0e0e0, 1.0);
|
[self.view addSubview:progressView];
|
self.progressView = progressView;
|
}
|
|
- (void)dealloc {
|
NSLog(@"%s",__FUNCTION__);
|
}
|
|
#pragma mark - event
|
- (void)back:(UIButton *)sender
|
{
|
if ([self.webView canGoBack]) {
|
[self.webView goBack];
|
|
} else {
|
!_shonpingShareBack?:_shonpingShareBack();
|
if ([self.shonpingSharedelegate respondsToSelector:@selector(noticeRewardCouponsViewBack)]) {
|
[self.shonpingSharedelegate noticeRewardCouponsViewBack];
|
};
|
[self.navigationController popViewControllerAnimated:YES];
|
}
|
}
|
|
- (void)shareTaped:(UIButton *)sender {
|
[self.dataMutArr removeAllObjects];
|
|
if (self.newAddmMutArr.count != 0) {
|
[self.dataMutArr addObjectsFromArray:self.newAddmMutArr];
|
}
|
[self.dataMutArr addObjectsFromArray:self.gudingArr];
|
|
self.webMorePopView = [[WebMorePopView alloc] initShareRecordPopView:self.dataMutArr];
|
@weakify(self)
|
self.webMorePopView.selectIndex = ^(NSInteger index) {
|
@strongify(self)
|
NSString *performJs = self.dataMutArr[index][@"js"];
|
if ([performJs isEqualToString:@"refresh"]) {
|
[self.webView reload];
|
|
} else if ([performJs isEqualToString:@"kefu"]) {
|
[CustomerServiceManage pushinitMQ:@"web"];
|
|
} else {
|
@weakify(self)
|
dispatch_async(dispatch_get_main_queue(), ^{
|
@strongify(self)
|
[self.webView evaluateJavaScript:performJs completionHandler:^(id _Nullable result, NSError * _Nullable error) {
|
NSLog(@"result:%@,error:%@",result,error);
|
}];
|
});
|
}
|
};
|
[self.webMorePopView show];
|
}
|
|
- (void)closeItem:(UIButton *)sender {
|
!_shonpingShareBack?:_shonpingShareBack();
|
if ([self.shonpingSharedelegate respondsToSelector:@selector(noticeRewardCouponsViewBack)]) {
|
[self.shonpingSharedelegate noticeRewardCouponsViewBack];
|
};
|
[self.navigationController popViewControllerAnimated:YES];
|
}
|
|
#pragma mark - private method
|
/// 获取用户ID
|
- (NSString *)getUid {
|
NSString *uid = [NSString stringWithFormat:@"%@",[ALUserInfoServiceManger fetchUID]];
|
if(![ALUserInfoServiceManger fetchUID]){
|
uid = @"0";
|
}
|
return uid;
|
}
|
- (NSString *)getVersion {
|
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
|
return version;
|
}
|
|
- (NSString *)getSign:(NSString *)stringJS {
|
if (!stringJS && [stringJS isEqualToString:@""]) {
|
return @"";
|
}
|
NSString *MD5String = [NSString md5:[NSString stringWithFormat:@"%@@?,223Hbb88lll",stringJS]];
|
return MD5String;
|
}
|
|
- (NSString *)getRequestBaseParams:(NSString *)stringJS {
|
NSDictionary *tempParms = nil;
|
if (stringJS) {
|
// 将JSON字符串转化为NSData类型
|
NSData *data = [stringJS dataUsingEncoding:NSUTF8StringEncoding];
|
tempParms = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
|
}
|
NSString *device = [FileSignature fetchUUID];
|
NSString *AppSecre = @"23649898";
|
NSString *apiversion = @"1";
|
NSString *platform = @"ios";
|
NSString *appid = @"24567001";
|
|
NSMutableDictionary *dic = [[NSMutableDictionary alloc] initWithDictionary:tempParms];
|
|
[dic setObject:AppSecre forKey:@"appkey"];
|
[dic setObject:device forKey:@"device"];
|
[dic setObject:Package forKey:@"packages"];
|
[dic setObject:Version forKey:@"version"];
|
[dic setObject:apiversion forKey:@"apiversion"];
|
[dic setObject:platform forKey:@"platform"];
|
[dic setObject:appid forKey:@"appid"];
|
[dic setObject:[FileSignature deviceType] forKey:@"deviceType"];
|
[dic setObject:[[UIDevice currentDevice] systemVersion] forKey:@"osVersion"];
|
[dic setObject:@"appstore" forKey:@"channel"];
|
if ([ALUserInfoServiceManger fetchUID]) {
|
[dic setObject:[ALUserInfoServiceManger fetchUID] forKey:@"uid"];
|
}
|
// 用户是否打开了广告标识符
|
BOOL isIDFA = [[ASIdentifierManager sharedManager] isAdvertisingTrackingEnabled];
|
if (isIDFA) {
|
[dic setObject:[self getIDFA] forKey:@"idfa"];
|
}
|
//现在的时间
|
NSTimeInterval timeNow = [[NSDate date] timeIntervalSince1970];
|
long long int date = (long long int)timeNow*1000;
|
NSString *timeStr=[NSString stringWithFormat:@"%lld",date];
|
[dic setObject:timeStr forKey:@"time"];
|
|
NSString *sign = [self sortingDictionaryWithdic:dic];
|
[dic setValue:sign forKey:@"sign"];
|
|
NSString *res = [NSString muiReactiveSendPersonInfo:dic];
|
return res;
|
}
|
|
- (void)toast:(NSString *)jsStringN
|
{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
if (jsStringN) {
|
[JRToast showWithText:jsStringN bottomOffset:kToolBarH + 15 duration:1.5];
|
}
|
});
|
}
|
|
- (void)jumpGoodsSplash:(NSString *)jsStringN {
|
@weakify(self)
|
dispatch_async(dispatch_get_main_queue(), ^{
|
@strongify(self)
|
NSDictionary *dic = @{@"type":@"new",@"id":[NSString stringWithFormat:@"%@",jsStringN]};
|
[self pushjumpGoodsSplashs:dic];
|
});
|
}
|
|
- (void)jumpGoodsSplashWithFrom:(NSDictionary *)dictionaryJS {
|
@weakify(self)
|
dispatch_async(dispatch_get_main_queue(), ^{
|
@strongify(self)
|
NSString *idString = [NSString stringWithFormat:@"%@",dictionaryJS[@"id"]];
|
NSString *from = dictionaryJS[@"from"];
|
NSDictionary *dic = @{@"type":@"new",@"id":idString,@"from":from?:@""};
|
[self pushjumpGoodsSplashs:dic];
|
});
|
}
|
|
- (void)jumpGoodsDetail:(NSString *)jsStringN {
|
@weakify(self)
|
dispatch_async(dispatch_get_main_queue(), ^{
|
@strongify(self)
|
NSDictionary *dic = @{@"type":@"old",@"id":[NSString stringWithFormat:@"%@",jsStringN]};
|
[self pushjumpGoodsSplashs:dic];
|
});
|
}
|
|
- (void)pushjumpGoodsSplashs:(NSDictionary *)dictionaryData {
|
NSString *type = dictionaryData[@"type"];
|
NSString *goodID = dictionaryData[@"id"];
|
NSString *fome = dictionaryData[@"from"];
|
|
if ([type isEqualToString:@"new"]) {
|
GoodDeTrViewController *goodsDetailVC = [[GoodDeTrViewController alloc]init];
|
goodsDetailVC.goodsID = goodID;
|
goodsDetailVC.from = fome;
|
goodsDetailVC.goodsType = 1;
|
[self .navigationController pushViewController:goodsDetailVC animated:YES];
|
|
} else {
|
SureWebViewController *webView = [[SureWebViewController alloc] init];
|
webView.goodsId = goodID;
|
webView.canDownRefresh = YES;
|
webView.isGoodsDetail = YES;
|
[self.navigationController pushViewController:webView animated:YES];
|
}
|
}
|
|
- (void)jumpKeFu:(NSString *)jsStringN {
|
dispatch_async(dispatch_get_main_queue(), ^{
|
[CustomerServiceManage pushinitMQ:jsStringN];
|
});
|
}
|
|
- (void)jumpBaiChuan:(NSDictionary *)dictionaryJS {
|
@weakify(self)
|
dispatch_async(dispatch_get_main_queue(), ^{
|
@strongify(self)
|
NSData *data = [dictionaryJS
|
[@"tbPid"] dataUsingEncoding:NSUTF8StringEncoding];
|
NSDictionary *tempParms = nil;
|
if (data) {
|
tempParms = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
|
}
|
|
NSString *goodId = dictionaryJS[@"id"];
|
NSString *url = dictionaryJS[@"url"];
|
|
AlibcTradeTaokeParams *taokeParams = [[AlibcTradeTaokeParams alloc] init];
|
if (tempParms) {
|
taokeParams.pid = tempParms[@"pid"]; //mm_XXXXX为你自己申请的阿里妈妈淘客pid
|
taokeParams.adzoneId = tempParms[@"adZoneId"];
|
taokeParams.extParams = @{@"taokeAppkey":tempParms[@"appKey"]};
|
|
} else {
|
taokeParams = nil;
|
}
|
|
if (url && ![url isEqualToString:@""]) {
|
[self.albcServiceManager pushOpenByUrl:url identity:nil webView:nil parentController:self.navigationController taoKeParams:taokeParams];
|
|
} else {
|
id<AlibcTradePage> page = [AlibcTradePageFactory itemDetailPage:[NSString stringWithFormat:@"%@",goodId]];
|
[self.albcServiceManager pushOpenByBizCode:@"detail" page:page webView:nil parentController:self.navigationController taoKeParams:taokeParams];
|
}
|
});
|
}
|
|
- (void)jumpPage:(NSDictionary *)dictionaryJS {
|
@weakify(self)
|
dispatch_async(dispatch_get_main_queue(), ^{
|
@strongify(self)
|
NSError *error;
|
NSData *jsonData = [dictionaryJS[@"params"] dataUsingEncoding:NSUTF8StringEncoding];
|
NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
|
NSDictionary *dic = nil;
|
if (jsonDic) {
|
dic = @{@"pageClassName" : dictionaryJS[@"controller"], @"paramsJSON" : jsonDic};
|
|
} else {
|
dic = @{@"pageClassName" : dictionaryJS[@"controller"]};
|
}
|
if([[dic[@"paramsJSON"] allKeys] count] <= 0) {
|
[self pushAnyInterfaceController:dic[@"pageClassName"] parms:nil];
|
return ;
|
}
|
[self pushAnyInterfaceController:dic[@"pageClassName"] parms:dic];
|
});
|
}
|
|
- (void)jumpPageWithFinishCurrentPage:(NSDictionary *)dictionaryJS {
|
@weakify(self)
|
dispatch_async(dispatch_get_main_queue(), ^{
|
@strongify(self)
|
NSError *error;
|
NSData *jsonData = [dictionaryJS[@"params"] dataUsingEncoding:NSUTF8StringEncoding];
|
NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
|
NSDictionary *dic = nil;
|
if (jsonDic) {
|
dic = @{@"pageClassName" : dictionaryJS[@"controller"], @"paramsJSON" : jsonDic};
|
|
} else {
|
dic = @{@"pageClassName" : dictionaryJS[@"controller"]};
|
}
|
[self pushAnyInterfaceController:dic[@"pageClassName"] parms:dic];
|
NSMutableArray *navigationVcMut = [[NSMutableArray alloc] initWithArray:self.navigationController.viewControllers];
|
for (int i = 0; i < navigationVcMut.count; i++) {
|
if (i == navigationVcMut.count - 2) {
|
[navigationVcMut removeObjectAtIndex:i];
|
self.navigationController.viewControllers = navigationVcMut;
|
break;
|
}
|
}
|
});
|
}
|
|
- (void)umEventCount:(NSDictionary *)dictionaryJS {
|
NSDictionary *dic = @{@"eventId":dictionaryJS[@"key"],@"paramsJSON":dictionaryJS[@"params"]};
|
NSString *eventId = dic[@"eventId"];
|
NSString *paramsJSON = dic[@"paramsJSON"];
|
NSDictionary *dic1 = [self dictionaryWithJsonString:paramsJSON];
|
[MobClick event:eventId attributes:dic1];
|
}
|
|
- (void)umEventCompute:(NSDictionary *)dictionaryJS {
|
NSDictionary *dic = @{@"eventId":dictionaryJS[@"key"],@"paramsJSON":dictionaryJS[@"params"],@"du":[NSString stringWithFormat:@"%@",dictionaryJS[@"du"]]};
|
NSString *eventId = dic[@"eventId"];
|
NSString *paramsJSON = dic[@"paramsJSON"];
|
int du = [dic[@"du"] intValue];
|
NSDictionary *dic1 = [self dictionaryWithJsonString:paramsJSON];
|
[MobClick event:eventId attributes:dic1 counter:du];
|
}
|
|
- (void)hiddenTopMenuCloseBtn {
|
@weakify(self)
|
dispatch_async(dispatch_get_main_queue(), ^{
|
@strongify(self)
|
self.closeButton.hidden = YES;
|
});
|
}
|
|
- (void)showSharePanel {
|
@weakify(self)
|
dispatch_async(dispatch_get_main_queue(), ^{
|
@strongify(self)
|
[self.shareDictionary setObject:self.urlShare forKey:@"url"];
|
self.shareAppView = [[SJDynamicShareView alloc] initShareAppView];
|
@weakify(self)
|
self.shareAppView.haveIndex = ^(NSString *type) {
|
@strongify(self)
|
[self.shareAppView dismiss];
|
self.shareAppView = nil;
|
|
if ([type isEqualToString:@"微信好友"]) {
|
[self shareWebToPlatformType:UMSocialPlatformType_WechatSession withtype:SSDKPlatformSubTypeWechatSession];
|
|
} else if ([type isEqualToString:@"朋友圈"]) {
|
[self shareWebToPlatformType:UMSocialPlatformType_WechatTimeLine withtype:SSDKPlatformSubTypeWechatTimeline];
|
|
} else if ([type isEqualToString:@"新浪微博"]) {
|
[self shareWebToPlatformType:UMSocialPlatformType_Sina withtype:SSDKPlatformTypeSinaWeibo];
|
|
} else if ([type isEqualToString:@"QQ好友"]) {
|
[self shareWebToPlatformType:UMSocialPlatformType_QQ withtype:SSDKPlatformSubTypeQQFriend];
|
|
} else if ([type isEqualToString:@"QQ空间"]) {
|
[self shareWebToPlatformType:UMSocialPlatformType_Qzone withtype:SSDKPlatformSubTypeQZone];
|
}
|
};
|
[self.shareAppView show];
|
});
|
}
|
|
/// 分享
|
/// @param platformType 类型
|
/// @param shareType 类型
|
- (void)shareWebToPlatformType:(UMSocialPlatformType)platformType withtype:(SSDKPlatformType) shareType {
|
SSDKContentType type = SSDKContentTypeAuto;
|
type = SSDKContentTypeWebPage;
|
if (shareType == SSDKPlatformSubTypeWechatTimeline || shareType == SSDKPlatformSubTypeWechatSession) {
|
if (![WXApi isWXAppInstalled]) {
|
[JRToast showWithText:@"微信未安装" bottomOffset:kToolBarH duration:1.5];
|
return;
|
}
|
}
|
|
if ( SSDKPlatformSubTypeQQFriend == shareType || shareType == SSDKPlatformSubTypeQZone ) {
|
if (![[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"mqq://"]]) {
|
[JRToast showWithText:@"QQ未安装" bottomOffset:kToolBarH duration:1.5];
|
return;
|
}
|
}
|
|
NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
|
[shareParams SSDKSetupShareParamsByText:@"" images:[UIImage imageNamed:@"聊天小程序头像"] url:self.shareDictionary[@"url"] title:self.shareDictionary[@"name"] type:type];
|
|
//进行分享
|
[ShareSDK share:shareType //传入分享的平台类型
|
parameters:shareParams
|
onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) { // 回调处理....}];
|
switch (state) {
|
case SSDKResponseStateSuccess:
|
{
|
break;
|
}
|
case SSDKResponseStateFail:
|
{
|
break;
|
}
|
default:
|
break;
|
}
|
}];
|
}
|
|
- (void)addMenu:(NSString *)arraryJS {
|
NSArray *array = nil;
|
|
@try {
|
NSData *jsonData = [arraryJS dataUsingEncoding:NSUTF8StringEncoding];
|
array = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
|
|
} @catch (NSException *exception) {
|
|
|
} @finally {
|
if (!array) {
|
array = (NSArray *)arraryJS;
|
}
|
}
|
|
|
if (![self isHaveValue:array]) {
|
return;
|
}
|
[self.newAddmMutArr removeAllObjects];
|
for (NSDictionary *dictionary in array) {
|
NSDictionary *dics = @{@"iconName":dictionary[@"name"],@"iconImage":dictionary[@"icon"],@"js":dictionary[@"js"]};
|
[self.newAddmMutArr addObject:dics];
|
}
|
}
|
|
- (void)copyText:(NSString *)jsStringN {
|
dispatch_async(dispatch_get_main_queue(), ^{
|
[self.commonMethodManage setPasteboardContent:jsStringN title:nil];
|
});
|
}
|
|
- (void)jumpSearch:(NSString *)jsStringN {
|
@weakify(self)
|
dispatch_async(dispatch_get_main_queue(), ^{
|
@strongify(self)
|
SearchDetailMainController *searchVc = [[SearchDetailMainController alloc] init];
|
searchVc.searchKey = jsStringN;
|
@weakify(self)
|
searchVc.searchSelect = ^(NSString * _Nonnull searchstring, NSInteger goodsTypes) {
|
@strongify(self)
|
[self cacheHistorySearch:searchstring goodsTypes:goodsTypes];
|
};
|
[self.navigationController pushViewController:searchVc animated:YES];
|
});
|
}
|
/// 储存搜索纪录
|
/// @param text 关键字
|
/// @param goodsTypes 类型
|
- (void)cacheHistorySearch:(NSString *)text goodsTypes:(NSInteger)goodsTypes {
|
self.plist.dataName = [self fetchplistNames:goodsTypes];
|
[self.tempOldArr removeAllObjects];
|
[self.tempOldArr addObjectsFromArray:[self.plist readFile][0]];
|
|
for (NSString *name in self.tempOldArr) {
|
if ([name isEqualToString:text]) {
|
[self.tempOldArr removeObject:name];
|
break;
|
}
|
}
|
[self.tempOldArr insertObject:text atIndex:0];
|
|
if (self.tempOldArr.count > 10) {
|
[self.tempOldArr removeObjectAtIndex:self.tempOldArr.count - 1];
|
}
|
|
self.plist.dataName = [self fetchplistNames:goodsTypes];
|
[self.plist writeFileWithData:self.tempOldArr];
|
}
|
|
- (NSString *)fetchplistNames:(NSInteger)goodsTypes {
|
NSString *name = nil;
|
if (goodsTypes == 1) {
|
name = @"historyTBSearchList";
|
|
} else if (goodsTypes == 2) {
|
name = @"historyJDSearchList";
|
|
} else if (goodsTypes == 3) {
|
name = @"historyPDDSearchList";
|
}
|
return name;
|
}
|
|
- (void)jumpInvite {
|
@weakify(self)
|
dispatch_async(dispatch_get_main_queue(), ^{
|
@strongify(self)
|
InvitationFriendsViewController *invitationFriendsVc = [[InvitationFriendsViewController alloc] init];
|
invitationFriendsVc.isRequestAPI = YES;
|
[self.navigationController pushViewController:invitationFriendsVc animated:YES];
|
});
|
}
|
|
- (void)login {
|
@weakify(self)
|
dispatch_async(dispatch_get_main_queue(), ^{
|
@strongify(self)
|
[JRToast showWithText:@"请先登录板栗快省账号" bottomOffset:kToolBarH duration:1.2f];
|
NewLoginViewController *loginVc = [[NewLoginViewController alloc] init];
|
loginVc.delegate = self;
|
loginVc.rootVc = self;
|
loginVc.vcName = @"webLogin";
|
[self.navigationController pushViewController:loginVc animated:YES];
|
});
|
}
|
|
- (void)noticeMineBackEvent:(NSString *)vcName {
|
if ([vcName isEqualToString:@"webLogin"]) {
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"noticeMessageVcUpdateData" object:nil];
|
[self.messageManger getMessage];
|
}
|
}
|
|
- (void)setTitles:(NSString *)jsStringN {
|
@weakify(self)
|
dispatch_async(dispatch_get_main_queue(), ^{
|
@strongify(self)
|
NSString *title = jsStringN;
|
self.urlName = title;
|
self.title = title;
|
[self.shareDictionary setObject:self.urlName forKey:@"name"];
|
});
|
}
|
|
- (void)showLoading {
|
@weakify(self)
|
dispatch_async(dispatch_get_main_queue(), ^{
|
@strongify(self)
|
[self.view makeToastActivity:CSToastPositionCenter];
|
});
|
}
|
|
- (void)hideLoading {
|
@weakify(self)
|
dispatch_async(dispatch_get_main_queue(), ^{
|
@strongify(self)
|
[self.view hideToastActivity];
|
});
|
}
|
|
- (void)finishPage
|
{
|
@weakify(self)
|
dispatch_async(dispatch_get_main_queue(), ^{
|
@strongify(self)
|
[self.navigationController popViewControllerAnimated:YES];
|
});
|
}
|
|
- (void)jumpJDGoodsDetailWithFrom:(NSDictionary *)dictionaryJS
|
{
|
@weakify(self)
|
dispatch_async(dispatch_get_main_queue(), ^{
|
@strongify(self)
|
NSString *goodsId = dictionaryJS[@"id"];
|
NSString *from = dictionaryJS[@"from"];
|
JDGoodsDetailController *goodsDetailVC = [[JDGoodsDetailController alloc]init];
|
goodsDetailVC.goodsID = goodsId;
|
goodsDetailVC.from = from;
|
goodsDetailVC.goodsType = 2;
|
[self .navigationController pushViewController:goodsDetailVC animated:YES];
|
});
|
}
|
|
- (void)jumpPDDGoodsDetailWithFrom:(NSDictionary *)dictionaryJS
|
{
|
@weakify(self)
|
dispatch_async(dispatch_get_main_queue(), ^{
|
@strongify(self)
|
NSString *goodsId = dictionaryJS[@"id"];
|
NSString *from = dictionaryJS[@"from"];
|
PDDGoodsDetailController *goodsDetailVC = [[PDDGoodsDetailController alloc]init];
|
goodsDetailVC.goodsID = goodsId;
|
goodsDetailVC.from = from;
|
goodsDetailVC.goodsType = 3;
|
[self .navigationController pushViewController:goodsDetailVC animated:YES];
|
});
|
}
|
|
- (void)shareLink:(NSDictionary *)dictionaryJS {
|
@weakify(self)
|
dispatch_async(dispatch_get_main_queue(), ^{
|
@strongify(self)
|
if ([dictionaryJS[@"type"] integerValue] == 1) {
|
[self shareWebPageType:SSDKPlatformSubTypeWechatSession dictionaryData:dictionaryJS types:0];
|
|
} else if ([dictionaryJS[@"type"] integerValue] == 2) {
|
[self shareWebPageType:SSDKPlatformSubTypeWechatTimeline dictionaryData:dictionaryJS types:0];
|
|
} else if ([dictionaryJS[@"type"] integerValue] == 3) {
|
[self shareWebPageType:SSDKPlatformSubTypeQQFriend dictionaryData:dictionaryJS types:0];
|
|
} else if ([dictionaryJS[@"type"] integerValue] == 4) {
|
[self shareWebPageType:SSDKPlatformSubTypeQZone dictionaryData:dictionaryJS types:0];
|
|
} else if ([dictionaryJS[@"type"] integerValue] == 5) {
|
[self shareWebPageType:SSDKPlatformTypeSinaWeibo dictionaryData:dictionaryJS types:0];
|
}
|
});
|
}
|
|
- (void)shareImg:(NSDictionary *)dictionaryJS {
|
@weakify(self)
|
dispatch_async(dispatch_get_main_queue(), ^{
|
@strongify(self)
|
if ([dictionaryJS[@"type"] integerValue] == 1) {
|
[self shareWebPageType:SSDKPlatformSubTypeWechatSession dictionaryData:dictionaryJS types:1];
|
|
} else if ([dictionaryJS[@"type"] integerValue] == 2) {
|
[self shareWebPageType:SSDKPlatformSubTypeWechatTimeline dictionaryData:dictionaryJS types:1];
|
|
} else if ([dictionaryJS[@"type"] integerValue] == 3) {
|
[self shareWebPageType:SSDKPlatformSubTypeQQFriend dictionaryData:dictionaryJS types:1];
|
|
} else if ([dictionaryJS[@"type"] integerValue] == 4) {
|
[self shareWebPageType:SSDKPlatformSubTypeQZone dictionaryData:dictionaryJS types:1];
|
|
} else if ([dictionaryJS[@"type"] integerValue] == 5) {
|
[self shareWebPageType:SSDKPlatformTypeSinaWeibo dictionaryData:dictionaryJS types:1];
|
}
|
});
|
}
|
|
- (void)shareText:(NSDictionary *)dictionaryJS {
|
@weakify(self)
|
dispatch_async(dispatch_get_main_queue(), ^{
|
@strongify(self)
|
if ([dictionaryJS[@"type"] integerValue] == 1) {
|
[self shareWebPageType:SSDKPlatformSubTypeWechatSession dictionaryData:dictionaryJS types:2];
|
|
} else if ([dictionaryJS[@"type"] integerValue] == 2) {
|
[self shareWebPageType:SSDKPlatformSubTypeWechatTimeline dictionaryData:dictionaryJS types:2];
|
|
} else if ([dictionaryJS[@"type"] integerValue] == 3) {
|
[self shareWebPageType:SSDKPlatformSubTypeQQFriend dictionaryData:dictionaryJS types:2];
|
|
} else if ([dictionaryJS[@"type"] integerValue] == 4) {
|
[self shareWebPageType:SSDKPlatformSubTypeQZone dictionaryData:dictionaryJS types:2];
|
|
} else if ([dictionaryJS[@"type"] integerValue] == 5) {
|
[self shareWebPageType:SSDKPlatformTypeSinaWeibo dictionaryData:dictionaryJS types:2];
|
}
|
});
|
}
|
|
- (void)savePicture:(NSString *)stringJS {
|
@weakify(self)
|
dispatch_async(dispatch_get_main_queue(), ^{
|
@strongify(self)
|
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:stringJS]]];
|
UIImageWriteToSavedPhotosAlbum(image, self, @selector(savedPhotoImage:didFinishSavingWithError:contextInfo:), nil);
|
});
|
}
|
|
- (void)savedPhotoImage:(UIImage*)image didFinishSavingWithError :(NSError *)error contextInfo: (void *)contextInfo {
|
if (_isDownMoreImg) {
|
if (error) {
|
|
} else {
|
[_arrayShareImage removeObjectAtIndex:0];
|
}
|
[self saveToAlbumNext];
|
|
} else {
|
if (!error) {
|
ALToastCenter(@"图片保存到相册成功");
|
}
|
}
|
}
|
|
/// 分享
|
/// @param shareType 分享类型
|
/// @param dictionaryData 分享数据
|
/// @param types 0-link 1-图片 2-纯文字 3-多图片
|
- (void)shareWebPageType:(SSDKPlatformType)shareType dictionaryData:(id)dictionaryData types:(NSInteger)types {
|
|
SSDKContentType type = SSDKContentTypeAuto;
|
if (shareType == SSDKPlatformSubTypeWechatTimeline || shareType == SSDKPlatformSubTypeWechatSession) {
|
if (![WXApi isWXAppInstalled]) {
|
[JRToast showWithText:@"微信未安装" bottomOffset:kToolBarH duration:1.5f];
|
return;
|
}
|
}
|
|
if ( SSDKPlatformSubTypeQQFriend == shareType || shareType == SSDKPlatformSubTypeQZone ) {
|
if (![[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"mqq://"]]) {
|
[JRToast showWithText:@"QQ未安装" bottomOffset:kToolBarH duration:1.5f];
|
return;
|
}
|
}
|
NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
|
if (types == 0) {
|
[shareParams SSDKSetupShareParamsByText:dictionaryData[@"content"] images:dictionaryData[@"img"] url:dictionaryData[@"url"] title:dictionaryData[@"title"] type:type];
|
|
} else if (types == 1) {
|
[shareParams SSDKSetupShareParamsByText:nil images:dictionaryData[@"url"] url:nil title:nil type:type];
|
|
} else if (types == 2) {
|
[shareParams SSDKSetupShareParamsByText:dictionaryData[@"text"] images:nil url:nil title:nil type:type];
|
|
} else if (types == 3) {
|
[shareParams SSDKSetupShareParamsByText:nil images:(NSArray *)dictionaryData url:nil title:nil type:type];
|
}
|
|
//进行分享
|
[ShareSDK share:shareType //传入分享的平台类型
|
parameters:shareParams
|
onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) { // 回调处理....}];
|
switch (state) {
|
case SSDKResponseStateSuccess:
|
{
|
break;
|
}
|
case SSDKResponseStateFail:
|
{
|
break;
|
}
|
default:
|
break;
|
}
|
}];
|
}
|
|
- (NSString *)screeningTbId:(NSString *)url {
|
if ([url rangeOfString:@"//detail.m.tmall.com/item.htm?"].location != NSNotFound ||
|
[url rangeOfString:@"//h5.m.taobao.com/awp/core/detail.htm?"].location != NSNotFound ||
|
[url rangeOfString:@"//detail.m.tmall.hk/item.htm?"].location != NSNotFound ||
|
[url rangeOfString:@"//detail.m.tmall.com/templatesNew/index?"].location != NSNotFound) {
|
|
NSString *goodsDetailId = nil;
|
NSArray *questionSegmentationArr = [url componentsSeparatedByString:@"?"];
|
NSArray *andSegmentationArr = [questionSegmentationArr[1] componentsSeparatedByString:@"&"];
|
|
for (NSString *temp in andSegmentationArr) {
|
if ([temp hasPrefix:@"id="]) {
|
NSArray *goodsIdArr = [temp componentsSeparatedByString:@"="];
|
goodsDetailId = goodsIdArr[1];
|
break;
|
}
|
}
|
return goodsDetailId;
|
|
} else if ([url rangeOfString:@"//ju.taobao.com/m/jusp/alone/detailwap/mtp.htm?"].location != NSNotFound) {
|
|
NSString *goodsDetailId = nil;
|
NSArray *questionSegmentationArr = [url componentsSeparatedByString:@"?"];
|
NSArray *andSegmentationArr = [questionSegmentationArr[1] componentsSeparatedByString:@"&"];
|
|
for (NSString *temp in andSegmentationArr) {
|
if ([temp hasPrefix:@"item_id="]) {
|
NSArray *goodsIdArr = [temp componentsSeparatedByString:@"="];
|
goodsDetailId = goodsIdArr[1];
|
break;
|
}
|
}
|
return goodsDetailId;
|
}
|
return nil;
|
}
|
|
- (NSString *)screeningJdId:(NSString *)url {
|
if ([url rangeOfString:@"https://item.m.jd.com/product/"].location != NSNotFound ||
|
[url rangeOfString:@"http://item.m.jd.com/product/"].location != NSNotFound ||
|
[url rangeOfString:@"https://item.jd.com/"].location != NSNotFound ||
|
[url rangeOfString:@"http://item.jd.com/"].location != NSNotFound) {
|
|
NSString *goodsDetailId = nil;
|
NSArray *questionSegmentationArr = [url componentsSeparatedByString:@"?"];
|
NSArray *andSegmentationArr = [questionSegmentationArr[0] componentsSeparatedByString:@"/"];
|
NSArray *indexArr = [andSegmentationArr[andSegmentationArr.count - 1] componentsSeparatedByString:@"."];
|
goodsDetailId = indexArr[0];
|
return goodsDetailId;
|
|
} else if ([url rangeOfString:@"https://item.m.jd.com/ware/view.action?"].location != NSNotFound) {
|
|
NSString *goodsDetailId = nil;
|
NSArray *questionSegmentationArr = [url componentsSeparatedByString:@"?"];
|
NSArray *andSegmentationArr = [questionSegmentationArr[1] componentsSeparatedByString:@"&"];
|
|
for (NSString *temp in andSegmentationArr) {
|
if ([temp hasPrefix:@"wareId="]) {
|
NSArray *goodsIdArr = [temp componentsSeparatedByString:@"="];
|
goodsDetailId = goodsIdArr[1];
|
break;
|
}
|
}
|
return goodsDetailId;
|
}
|
return nil;
|
}
|
|
- (NSString *)screeningPddId:(NSString *)url {
|
if ([url rangeOfString:@"://mobile.yangkeduo.com/goods.html?"].location != NSNotFound ||
|
[url rangeOfString:@"yangkeduo.com/duo_coupon_landing.html?"].location != NSNotFound ||
|
[url rangeOfString:@"://mobile.yangkeduo.com/goods2.html?"].location != NSNotFound) {
|
|
NSString *goodsDetailId = nil;
|
NSArray *questionSegmentationArr = [url componentsSeparatedByString:@"?"];
|
NSArray *andSegmentationArr = [questionSegmentationArr[1] componentsSeparatedByString:@"&"];
|
|
for (NSString *temp in andSegmentationArr) {
|
if ([temp hasPrefix:@"goods_id="]) {
|
NSArray *goodsIdArr = [temp componentsSeparatedByString:@"="];
|
goodsDetailId = goodsIdArr[1];
|
break;
|
}
|
}
|
return goodsDetailId;
|
}
|
return nil;
|
}
|
|
- (BOOL)isPureInt:(NSString*)string {
|
NSScanner* scan = [NSScanner scannerWithString:string];
|
int val;
|
return[scan scanInt:&val] && [scan isAtEnd];
|
}
|
|
- (NSString *)screeningWPHId:(NSString *)url {
|
if (([url rangeOfString:@".vip.com/"].location != NSNotFound &&
|
[url rangeOfString:@"detail-"].location != NSNotFound) ||
|
[url rangeOfString:@"product-"].location != NSNotFound) {
|
|
if ([self.from isEqualToString:@"goodsDetail"]) {
|
return nil;
|
}
|
|
NSString *goodsDetailId = nil;
|
NSArray *questionSegmentationArr = [url componentsSeparatedByString:@"?"];
|
NSArray *andSegmentationArr = [questionSegmentationArr[0] componentsSeparatedByString:@"-"];
|
|
for (NSString *temp in andSegmentationArr) {
|
if ([temp hasSuffix:@".html"]) {
|
goodsDetailId = [temp stringByReplacingOccurrencesOfString:@".html" withString:@""];
|
if ([self isPureInt:goodsDetailId]) {
|
break;
|
|
} else {
|
goodsDetailId = nil;
|
}
|
}
|
}
|
return goodsDetailId;
|
}
|
return nil;
|
}
|
|
- (NSString *)screeningSNId:(NSString *)url {
|
if (([url rangeOfString:@"suning.com/"].location != NSNotFound &&
|
[url rangeOfString:@"suning.com/product/"].location != NSNotFound) ||
|
[url rangeOfString:@"product.suning.com/"].location != NSNotFound) {
|
|
if ([self.from isEqualToString:@"goodsDetail"]) {
|
return nil;
|
}
|
|
NSMutableString *goodsDetailId = [[NSMutableString alloc] init];
|
|
NSArray *questionSegmentationArr = [url componentsSeparatedByString:@"?"];
|
NSArray *andSegmentationArr = [questionSegmentationArr[0] componentsSeparatedByString:@"/"];
|
|
for (NSString *temp in andSegmentationArr) {
|
NSString *tempName = [temp stringByReplacingOccurrencesOfString:@".html" withString:@""];
|
|
if ([self isPureInt:tempName]) {
|
[goodsDetailId appendString:tempName];
|
}
|
}
|
return goodsDetailId;
|
}
|
return nil;
|
}
|
|
- (void)jumpJD:(NSDictionary *)dictionary {
|
@weakify(self)
|
dispatch_async(dispatch_get_main_queue(), ^{
|
@strongify(self)
|
[self pushJingDong:YES jumpLink:dictionary[@"url"]];
|
});
|
}
|
|
- (void)tbAuth:(NSDictionary *)dictionary {
|
@weakify(self)
|
dispatch_async(dispatch_get_main_queue(), ^{
|
@strongify(self)
|
[self.albcServiceManager pushAuthOpenByUrl:dictionary[@"url"] identity:nil parentController:self.navigationController];
|
});
|
}
|
|
- (void)clearClipboard {
|
[self.commonMethodManage clearClipboard];
|
}
|
|
//跳转微信小程序
|
- (void)jumpWXXCX:(NSDictionary *)dictionary {
|
[self.commonMethodManage launchMiniProgramWithUserName:dictionary[@"userName"] path:dictionary[@"path"] type:0];
|
}
|
|
- (void)shareWXXCX:(NSDictionary *)dictionary {
|
|
}
|
|
- (void)shareImgs:(NSDictionary *)dictionary {
|
NSString *jsonString = dictionary[@"imgUrls"];
|
if (!jsonString) return;
|
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
|
NSArray *array = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
|
|
NSMutableArray *mutArr = [[NSMutableArray alloc] init];
|
|
dispatch_async(dispatch_get_global_queue(0,0),^{
|
for (NSString *string in array) {
|
UIImage *iamge = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:string]]];
|
[mutArr addObject:iamge];
|
}
|
@weakify(self)
|
dispatch_async(dispatch_get_main_queue(),^{
|
@strongify(self)
|
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:mutArr applicationActivities:nil];
|
activityVC.excludedActivityTypes = @[UIActivityTypeAirDrop,UIActivityTypeMessage,UIActivityTypeMail];
|
activityVC.modalInPopover = YES;
|
activityVC.completionWithItemsHandler = ^(UIActivityType _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) {
|
if (completed == YES) {
|
NSLog(@"completed");
|
|
} else {
|
NSLog(@"cancel");
|
}
|
};
|
//4、调用控制器
|
[self presentViewController:activityVC animated:YES completion:nil];
|
});
|
});
|
}
|
|
- (void)savePictures:(NSString *)string {
|
if (!string) return;
|
NSData *jsonData = [string dataUsingEncoding:NSUTF8StringEncoding];
|
NSArray *array = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
|
|
[self.view makeToastActivity:CSToastPositionCenter];
|
self.view.userInteractionEnabled = NO;
|
self.isDownMoreImg = YES;
|
[self.arrayShareImage removeAllObjects];
|
@weakify(self)
|
dispatch_async(dispatch_get_global_queue(0,0),^{
|
@strongify(self)
|
for (NSString *string in array) {
|
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:string]]];
|
[self.arrayShareImage addObject:image];
|
}
|
@weakify(self)
|
dispatch_async(dispatch_get_main_queue(),^{
|
@strongify(self)
|
[self saveToAlbumNext];
|
});
|
});
|
}
|
|
/// 保存相册
|
-(void)saveToAlbumNext {
|
if (_arrayShareImage.count > 0) {
|
UIImage *image = _arrayShareImage[0];
|
UIImageWriteToSavedPhotosAlbum(image, self, @selector(savedPhotoImage:didFinishSavingWithError:contextInfo:), nil);
|
|
} else {
|
[self allDone];
|
[self.view hideToastActivity];
|
self.view.userInteractionEnabled = YES;
|
}
|
}
|
|
- (void)allDone {
|
ALToastCenter(@"分享图保存成功");
|
}
|
|
- (void)showimgs:(NSDictionary *)dictionary {
|
NSData *jsonData = [dictionary[@"imgList"] dataUsingEncoding:NSUTF8StringEncoding];
|
NSArray *array = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
|
|
NSMutableArray *arrayImgs = [[NSMutableArray alloc] init];
|
for (NSDictionary *dictionary in array) {
|
[arrayImgs addObject:dictionary[@"url"]];
|
}
|
int index = 0;
|
if (dictionary[@"position"]) {
|
index = [dictionary[@"position"] intValue];
|
}
|
HZPhotoBrowser *browser = [[HZPhotoBrowser alloc] init];
|
browser.isFullWidthForLandScape = YES;
|
browser.isNeedLandscape = NO;
|
browser.currentImageIndex = index;
|
browser.imageArray = arrayImgs;
|
[browser show];
|
}
|
|
/**
|
* 拦截网页中的商品
|
*/
|
- (void)interceptWebGoods:(NSString *)goodsDetailId goodsType:(NSString *)goodsType {
|
@weakify(self)
|
[[ALNetWorking startInterface] Post:[NSString stringWithFormat:@"%@/%@",domainHTTP2,@"goods/isGoodsExtend"] param:@{@"goodsId":goodsDetailId,@"goodsType":goodsType} success:^(NSDictionary *object) {
|
@strongify(self)
|
@weakify(self)
|
dispatch_async(dispatch_get_main_queue(), ^{
|
@strongify(self)
|
if ([object[@"code"] integerValue] == 0) {
|
if ([object[@"data"][@"extend"] boolValue]) {
|
[self.commonMethodManage pushGoodsinfoDetail:goodsDetailId from:@"baichuanweb" goodsType:[goodsType integerValue]];
|
|
} else {
|
NoCouponNoRebateController *noCouponNoRebateVc = [[NoCouponNoRebateController alloc] init];
|
noCouponNoRebateVc.urlString = object[@"data"][@"url"];
|
[self.navigationController pushViewController:noCouponNoRebateVc animated:YES];
|
}
|
}
|
});
|
|
} fail:^(id object) {
|
|
}];
|
}
|
|
#pragma mark - KVO
|
// 计算wkWebView进度条
|
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
|
|
if (object == self.webView && [keyPath isEqualToString:@"estimatedProgress"]) {
|
CGFloat newprogress = [[change objectForKey:NSKeyValueChangeNewKey] doubleValue];
|
if (newprogress == 1) {
|
[self.progressView setProgress:1.0 animated:YES];
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.7 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
self.progressView.hidden = YES;
|
[self.progressView setProgress:0 animated:NO];
|
});
|
|
}else {
|
self.progressView.hidden = NO;
|
[self.progressView setProgress:newprogress animated:YES];
|
}
|
|
} else if ([keyPath isEqualToString:@"title"]) {//网页title
|
if (object == self.webView) {
|
if (self.navaTitle) {
|
self.urlName = self.navaTitle;
|
self.title = self.navaTitle;
|
|
} else {
|
self.urlName = self.webView.title;
|
self.title = self.webView.title;
|
}
|
[self.shareDictionary setObject:self.urlName forKey:@"name"];
|
|
} else {
|
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
|
}
|
|
} else {
|
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
|
}
|
}
|
|
#pragma mark - WKScriptMessageHandler
|
// 决定导航的动作,通常用于处理跨域的链接能否导航。
|
// WebKit对跨域进行了安全检查限制,不允许跨域,因此我们要对不能跨域的链接单独处理。
|
// 但是,对于Safari是允许跨域的,不用这么处理。
|
// 这个是决定是否Request
|
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
|
// 在发送请求之前,决定是否跳转
|
NSString * urlStr = navigationAction.request.URL.absoluteString;
|
|
if ([urlStr hasPrefix:@"itms-appss://"]) {
|
if ([[UIApplication sharedApplication] canOpenURL:navigationAction.request.URL]) {
|
[[UIApplication sharedApplication] openURL:navigationAction.request.URL];
|
decisionHandler(WKNavigationActionPolicyCancel);
|
return;
|
}
|
}
|
|
if ([urlStr hasPrefix:@"pinduoduo://"]) {
|
if ([[UIApplication sharedApplication] canOpenURL:navigationAction.request.URL]) {
|
[[UIApplication sharedApplication] openURL:navigationAction.request.URL];
|
decisionHandler(WKNavigationActionPolicyCancel);
|
return;
|
}
|
}
|
|
if ([urlStr hasPrefix:@"suning://"]) {
|
if ([[UIApplication sharedApplication] canOpenURL:navigationAction.request.URL]) {
|
[[UIApplication sharedApplication] openURL:navigationAction.request.URL];
|
decisionHandler(WKNavigationActionPolicyCancel);
|
return;
|
}
|
}
|
|
if ([urlStr hasPrefix:@"vipshop://"]) {
|
if ([[UIApplication sharedApplication] canOpenURL:navigationAction.request.URL]) {
|
[[UIApplication sharedApplication] openURL:navigationAction.request.URL];
|
decisionHandler(WKNavigationActionPolicyCancel);
|
return;
|
}
|
}
|
|
if ([urlStr rangeOfString:@"shop.banliapp.com://"].location != NSNotFound) {
|
// 设置webView的头部参数Referer
|
if (!navigationAction.request.allHTTPHeaderFields[@"Referer"]) {
|
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:navigationAction.request.URL];
|
[request setValue:@"shop.banliapp.com://" forHTTPHeaderField:@"Referer"];
|
[webView loadRequest:request];
|
}
|
}
|
|
if ([urlStr rangeOfString:@"shop.banliapp.com://"].location != NSNotFound) {
|
[webView goBack];
|
NSString *urlSecond = [navigationAction.request.URL.absoluteString stringByReplacingOccurrencesOfString:@"shop.banliapp.com://" withString:@"http://"];
|
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlSecond]]];
|
decisionHandler(WKNavigationActionPolicyCancel);
|
return;
|
}
|
|
// 拦截微信支付
|
if ([urlStr rangeOfString:@"weixin://wap/pay?"].location != NSNotFound) {
|
if ([WXApi isWXAppInstalled]) {
|
if (@available(iOS 10.0, *)) { // 10.0以上的版本
|
if([[UIApplication sharedApplication] respondsToSelector:@selector(openURL:options:completionHandler:)]) {
|
[[UIApplication sharedApplication] openURL:navigationAction.request.URL options:@{UIApplicationOpenURLOptionUniversalLinksOnly: @NO} completionHandler:nil];
|
}
|
|
} else { // 10.0以下的版本
|
if ([[UIApplication sharedApplication] respondsToSelector:@selector(openURL:)]) {
|
[[UIApplication sharedApplication] openURL:navigationAction.request.URL];
|
}
|
}
|
|
} else {
|
[JRToast showWithText:@"尚未安装微信" bottomOffset:kToolBarH + 15 duration:1.2f];
|
}
|
decisionHandler(WKNavigationActionPolicyCancel);
|
return;
|
}
|
|
BOOL isAllow = [CZBInfoManager webView:webView decidePolicyForNavigationAction:navigationAction];
|
if (!isAllow) {
|
WKNavigationActionPolicy actionPolicy = isAllow ? WKNavigationActionPolicyAllow:WKNavigationActionPolicyCancel;
|
decisionHandler(actionPolicy);
|
return;
|
}
|
|
if (![urlStr hasPrefix:@"http"]) {
|
decisionHandler(WKNavigationActionPolicyCancel);
|
return;
|
}
|
|
if ([urlStr rangeOfString:@"yestv://"].location !=NSNotFound || [urlStr rangeOfString:@"fanli://"].location !=NSNotFound ) {
|
NSArray *array = [urlStr componentsSeparatedByString:@"#"];
|
if ([array[0] isEqualToString:@"yestv://copy"]) {
|
NSData *decodedData = [[NSData alloc] initWithBase64EncodedString:array[1] options:0];
|
NSString *decodedString = [[NSString alloc] initWithData:decodedData encoding:NSUTF8StringEncoding];
|
[self.commonMethodManage setPasteboardContent:decodedString title:@"复制成功!"];
|
|
} else if ([array[0] isEqualToString:@"yestv://setShareBtn"]) {
|
|
} else if ([array[0] isEqualToString:@"yestv://toast"]) {
|
ALToastBottom([GTMBase64 decodeBase64String:array[1]]);
|
}
|
}
|
|
if (self.goodsDetail) {
|
NSString *tbId = [self screeningTbId:urlStr];
|
NSString *jdId = [self screeningJdId:urlStr];
|
NSString *pddId = [self screeningPddId:urlStr];
|
NSString *wphId = [self screeningWPHId:urlStr];
|
NSString *snId = [self screeningSNId:urlStr];
|
|
if (tbId) {
|
[self interceptWebGoods:tbId goodsType:@"1"];
|
|
} else if (jdId) {
|
[self interceptWebGoods:jdId goodsType:@"2"];
|
|
} else if (pddId) {
|
[self interceptWebGoods:pddId goodsType:@"3"];
|
|
} else if (wphId) {
|
[self interceptWebGoods:wphId goodsType:@"4"];
|
|
} else if (snId) {
|
[self interceptWebGoods:snId goodsType:@"5"];
|
|
}
|
|
if (tbId || jdId || pddId || wphId || snId) {
|
decisionHandler(WKNavigationActionPolicyCancel);
|
return;
|
}
|
}
|
|
if (navigationAction.targetFrame == nil) {
|
[webView loadRequest:navigationAction.request];
|
}
|
decisionHandler(WKNavigationActionPolicyAllow);
|
|
}
|
|
// 根据客户端受到的服务器响应头以及response相关信息来决定是否可以跳转
|
- (void)webView:(WKWebView *)webView
|
decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse
|
decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler {
|
// 在收到响应后,决定是否跳转和发送请求之前那个允许配套使用
|
decisionHandler(WKNavigationResponsePolicyAllow);
|
}
|
|
//用于授权验证的API,与AFN、UIWebView的授权验证API是一样的 需要响应身份验证时调用 同样在block中需要传入用户身份凭证
|
- (void)webView:(WKWebView *)webView
|
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
|
completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *__nullable credential))completionHandler {
|
|
completionHandler(NSURLSessionAuthChallengePerformDefaultHandling ,nil);
|
}
|
|
// 页面开始加载时调用
|
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation {
|
if (!self.navaTitle) {
|
self.title = @"网页加载中...";
|
|
} else {
|
self.title = self.navaTitle;
|
}
|
}
|
|
// 当main frame接收到服务重定向时调用
|
- (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(null_unspecified WKNavigation *)navigation {
|
// 接收到服务器跳转请求之后调用
|
}
|
|
// 页面加载失败时调用
|
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error {
|
if (![self socketReachabilityTest]) {
|
if (!self.navaTitle) {
|
self.title = @"网页无法打开";
|
|
} else {
|
self.title = self.navaTitle;
|
}
|
}
|
}
|
|
// 当内容开始返回时调用
|
- (void)webView:(WKWebView *)webView didCommitNavigation:(null_unspecified WKNavigation *)navigation {
|
|
}
|
|
// 页面加载完成之后调用
|
- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation {
|
NSString *urlRequestString = webView.URL.absoluteString;
|
self.urlShare = urlRequestString;
|
|
if (self.navaTitle) { // 设置标题
|
self.urlName = self.navaTitle;
|
self.title = self.navaTitle;
|
|
} else {
|
self.urlName = self.webView.title;
|
self.title = self.webView.title;
|
}
|
[self.shareDictionary setObject:self.urlName forKey:@"name"];
|
|
self.isWebViewLoad = YES;
|
}
|
// 当main frame最后下载数据失败时,会回调
|
- (void)webView:(WKWebView *)webView didFailNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error {
|
|
}
|
|
// 当web content处理完成时,会回调 进程被终止时调用
|
- (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView {
|
|
}
|
|
#pragma mark - UIDelegate
|
// JS端调用prompt函数时,会触发此代理方法。
|
- (void)webView:(WKWebView *)webView
|
runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt
|
defaultText:(nullable NSString *)defaultText
|
initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSString * __nullable result))completionHandler {
|
|
NSError *err = nil;
|
NSData *dataFromString = [prompt dataUsingEncoding:NSUTF8StringEncoding];
|
NSDictionary *payload = [NSJSONSerialization JSONObjectWithData:dataFromString options:NSJSONReadingMutableContainers error:&err];
|
if (!err)
|
{
|
NSString *type = [payload objectForKey:@"type"];
|
if (type && [type isEqualToString:@"getUid"]){
|
NSString *returnValue = [self getUid];
|
completionHandler(returnValue);
|
|
} else if (type && [type isEqualToString:@"getVersion"]){
|
NSString *returnValue = [self getVersion];
|
completionHandler(returnValue);
|
|
} else if (type && [type isEqualToString:@"getSign"]){
|
NSString *params = [payload objectForKey:@"params"];
|
NSString *returnValue = [self getSign:params];
|
completionHandler(returnValue);
|
|
} else if (type && [type isEqualToString:@"getRequestBaseParams"]){
|
NSString *params = [payload objectForKey:@"params"];
|
NSString *returnValue = [self getRequestBaseParams:params];
|
completionHandler(returnValue);
|
|
}
|
}
|
}
|
|
#pragma mark - WKScriptMessageHandler
|
- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message {
|
//message.body -- Allowed types are NSNumber, NSString, NSDate, NSArray,NSDictionary, and NSNull.
|
NSLog(@"body:%@",message.body);
|
if ([message.name isEqualToString:@"toast"]) {
|
[self toast:message.body];
|
|
} else if ([message.name isEqualToString:@"jumpGoodsSplash"]) {
|
[self jumpGoodsSplash:message.body];
|
|
} else if ([message.name isEqualToString:@"jumpGoodsSplashWithFrom"]) {
|
[self jumpGoodsSplashWithFrom:message.body];
|
|
} else if ([message.name isEqualToString:@"jumpGoodsDetail"]) {
|
[self jumpGoodsDetail:message.body];
|
|
} else if ([message.name isEqualToString:@"jumpKeFu"]) {
|
[self jumpKeFu:message.body];
|
|
} else if ([message.name isEqualToString:@"jumpBaiChuan"]) {
|
[self jumpBaiChuan:message.body];
|
|
} else if ([message.name isEqualToString:@"jumpPage"]) {
|
[self jumpPage:message.body];
|
|
} else if ([message.name isEqualToString:@"jumpPageWithFinishCurrentPage"]) {
|
[self jumpPageWithFinishCurrentPage:message.body];
|
|
} else if ([message.name isEqualToString:@"umEventCount"]) {
|
[self umEventCount:message.body];
|
|
} else if ([message.name isEqualToString:@"umEventCompute"]) {
|
[self umEventCompute:message.body];
|
|
} else if ([message.name isEqualToString:@"hiddenTopMenuCloseBtn"]) {
|
[self hiddenTopMenuCloseBtn];
|
|
} else if ([message.name isEqualToString:@"showSharePanel"]) {
|
[self showSharePanel];
|
|
} else if ([message.name isEqualToString:@"addMenu"]) {
|
[self addMenu:message.body];
|
|
} else if ([message.name isEqualToString:@"copyText"]) {
|
[self copyText:message.body];
|
|
} else if ([message.name isEqualToString:@"jumpSearch"]) {
|
[self jumpSearch:message.body];
|
|
} else if ([message.name isEqualToString:@"jumpInvite"]) {
|
[self jumpInvite];
|
|
} else if ([message.name isEqualToString:@"login"]) {
|
[self login];
|
|
} else if ([message.name isEqualToString:@"setTitle"]) {
|
[self setTitle:message.body];
|
|
} else if ([message.name isEqualToString:@"showLoading"]) {
|
[self showLoading];
|
|
} else if ([message.name isEqualToString:@"hideLoading"]) {
|
[self hideLoading];
|
|
} else if ([message.name isEqualToString:@"finishPage"]) {
|
[self finishPage];
|
|
} else if ([message.name isEqualToString:@"jumpJDGoodsDetailWithFrom"]) {
|
[self jumpJDGoodsDetailWithFrom:message.body];
|
|
} else if ([message.name isEqualToString:@"jumpPDDGoodsDetailWithFrom"]) {
|
[self jumpPDDGoodsDetailWithFrom:message.body];
|
|
} else if ([message.name isEqualToString:@"shareLink"]) {
|
[self shareLink:message.body];
|
|
} else if ([message.name isEqualToString:@"shareImg"]) {
|
[self shareImg:message.body];
|
|
} else if ([message.name isEqualToString:@"savePicture"]) {
|
[self savePicture:message.body];
|
|
} else if ([message.name isEqualToString:@"jumpJD"]) {
|
[self jumpJD:message.body];
|
|
} else if ([message.name isEqualToString:@"tbAuth"]) {
|
[self tbAuth:message.body];
|
|
} else if ([message.name isEqualToString:@"shareText"]) {
|
[self shareText:message.body];
|
|
} else if ([message.name isEqualToString:@"clearClipboard"]) {
|
[self clearClipboard];
|
|
} else if ([message.name isEqualToString:@"jumpWXXCX"]) {
|
[self jumpWXXCX:message.body];
|
|
} else if ([message.name isEqualToString:@"shareWXXCX"]) {
|
[self shareWXXCX:message.body];
|
|
} else if ([message.name isEqualToString:@"shareImgs"]) {
|
[self shareImgs:message.body];
|
|
} else if ([message.name isEqualToString:@"savePictures"]) {
|
[self savePictures:message.body];
|
|
} else if ([message.name isEqualToString:@"showimgs"]) {
|
[self showimgs:message.body];
|
}
|
}
|
|
- (NSString *)getIDFA {
|
SEL advertisingIdentifierSel = sel_registerName("advertisingIdentifier");
|
SEL UUIDStringSel = sel_registerName("UUIDString");
|
|
ASIdentifierManager *manager = [ASIdentifierManager sharedManager];
|
#pragma clang diagnostic push
|
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
|
if([manager respondsToSelector:advertisingIdentifierSel]) {
|
|
id UUID = [manager performSelector:advertisingIdentifierSel];
|
|
if([UUID respondsToSelector:UUIDStringSel]) {
|
|
return [UUID performSelector:UUIDStringSel];
|
}
|
}
|
#pragma clang diagnostic pop
|
return nil;
|
}
|
|
- (NSString *)sortingDictionaryWithdic:(NSDictionary *)dic {
|
NSMutableArray *array = @[].mutableCopy;
|
for (NSInteger index = 0; index < dic.allKeys.count; index ++) {
|
[array addObject:[NSString stringWithFormat:@"%@=%@",dic.allKeys[index],dic.allValues[index]]];
|
}
|
NSArray *resultArray = [array sortedArrayUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) {
|
/*
|
排序结果
|
NSComparisonResult resuest = [obj1 compare:obj2];为从小到大,即升序;
|
NSComparisonResult resuest = [obj2 compare:obj1];为从大到小,即降序;
|
注意:compare方法是区分大小写的,即按照ASCII排序
|
*/
|
//排序操作
|
NSComparisonResult resuest = [obj1 compare:obj2];
|
return resuest;
|
}];
|
|
NSString *resultString = @"";
|
for (NSInteger index = 0; index < resultArray.count; index ++) {
|
if (index == 0) {
|
resultString = [NSString stringWithFormat:@"%@",resultArray[index]];
|
continue;
|
}
|
resultString = [NSString stringWithFormat:@"%@&%@",resultString,resultArray[index]];
|
}
|
|
resultString = [resultString stringByAppendingString:@"&buXiNjie2017!"];
|
resultString = [NSString md5:resultString];
|
return resultString;
|
}
|
|
- (NSString *)convertToJsonData:(NSDictionary *)dict {
|
NSError *error;
|
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
|
NSString *jsonString;
|
if (!jsonData) {
|
NSLog(@"%@",error);
|
|
} else {
|
jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
|
}
|
return jsonString;
|
}
|
|
- (UIView *)navGaryLine {
|
if (!_navGaryLine) {
|
_navGaryLine = [[UIView alloc] init];
|
_navGaryLine.frame = CGRectMake(0, 0, SCREEN_WIDTH, 0.5);
|
_navGaryLine.backgroundColor = UIColorFromRGBValue(0xe0e0e0);
|
}
|
return _navGaryLine;
|
}
|
|
- (NSMutableArray *)dataMutArr {
|
if (!_dataMutArr) {
|
_dataMutArr = [[NSMutableArray alloc] init];
|
}
|
return _dataMutArr;
|
}
|
|
- (NSMutableArray *)newAddmMutArr {
|
if (!_newAddmMutArr) {
|
_newAddmMutArr = [[NSMutableArray alloc] init];
|
}
|
return _newAddmMutArr;
|
}
|
|
- (NSArray *)gudingArr {
|
if (!_gudingArr) {
|
_gudingArr = @[@{@"iconName" : @"刷新", @"iconImage" : @"web_refresh",@"js":@"refresh"},
|
@{@"iconName" : @"人工客服", @"iconImage" : @"web_rengong",@"js":@"kefu"}];
|
}
|
return _gudingArr;
|
}
|
|
- (NSMutableArray *)tempOldArr {
|
if (!_tempOldArr) {
|
_tempOldArr = [[NSMutableArray alloc] init];
|
}
|
return _tempOldArr;
|
}
|
|
- (NSMutableArray *)arrayShareImage {
|
if (!_arrayShareImage) {
|
_arrayShareImage = [[NSMutableArray alloc] init];
|
}
|
return _arrayShareImage;
|
}
|
|
@end
|