123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442 |
- //
- // newsDetailVController.m
- // ZhongJingLianMeng
- //
- // Created by youke on 2018/12/3.
- // Copyright © 2018 youke. All rights reserved.
- //
- #import "newsDetailVController.h"
- #import "UIAlertController+LY.h"
- #import <JavaScriptCore/JavaScriptCore.h>
- #import <ShareSDK/ShareSDK.h>
- #import <ShareSDKUI/ShareSDK+SSUI.h>
- #import "ZLCWebView.h"
- #import<ShareSDKUI/SSUIShareActionSheetStyle.h>//设置简单分享菜单样式
- #import "logInViewController.h"
- #import "activityDetailVController.h"
- @interface newsDetailVController ()<ZLCWebViewDelegate>
- @property (nonatomic, strong) ZLCWebView *webView;
- @property(nonatomic,strong) JSContext *jsContext;
- @property(nonatomic,strong)UIButton *collectionBtn;
- @property(nonatomic,strong)UIButton *shareBtn;
- @property (strong, nonatomic) HttpRequestManger *sessionManager;
- @property(nonatomic,strong)NSString *collectionStaus;
- @end
- @implementation newsDetailVController
- - (HttpRequestManger*) sessionManager{
-
- if (!_sessionManager) {
-
- _sessionManager = [[HttpRequestManger alloc]init];
-
- }
- return _sessionManager;
- }
- -(void)viewWillAppear:(BOOL)animated{
-
- [super viewWillAppear:YES];
-
- if ([_index isEqualToString:@"0"]) {
-
- [self loadIsCollection:self.typeStr];
- }
- }
- static void extracted(newsDetailVController *object, NSMutableDictionary *parma, newsDetailVController *const __weak weakself) {
- [object.sessionManager sendPostHttpRequestWithUrl:isCollection params:parma bodyBlock:nil progress:nil success:^(NSDictionary *response) {
-
- weakself.collectionStaus = response[@"isCollected"];
-
- if ([weakself.collectionStaus isEqualToString:@"1"]) {
-
- [weakself.collectionBtn setImage:[UIImage imageNamed:@"collection"] forState:UIControlStateNormal];
-
- }else{
-
- [weakself.collectionBtn setImage:[UIImage imageNamed:@"NoCollection"] forState:UIControlStateNormal];
-
- }
- } failure:^(NSError *error) {
-
- NSLog(@"%@",error);
- }];
- }
- -(void)loadIsCollection:(NSString *)typeString{
-
- if ([typeString isEqualToString:@"0"]) {
-
- kWeakSelf(self);
-
- NSMutableDictionary *parma = [NSMutableDictionary dictionary];
-
- parma[@"id"] = weakself.newsId;
- parma[@"type"] = @"0";
- self.sessionManager = [[HttpRequestManger alloc]init];
-
- extracted(self, parma, weakself);
-
-
- }else{
-
- kWeakSelf(self);
-
- NSMutableDictionary *parma = [NSMutableDictionary dictionary];
-
- parma[@"id"] = weakself.newsId;
- parma[@"type"] = @"2";
- self.sessionManager = [[HttpRequestManger alloc]init];
-
- [self.sessionManager sendPostHttpRequestWithUrl:isCollection params:parma bodyBlock:nil progress:nil success:^(NSDictionary *response) {
-
- weakself.collectionStaus = response[@"isCollected"];
-
- if ([weakself.collectionStaus isEqualToString:@"1"]) {
-
- [weakself.collectionBtn setImage:[UIImage imageNamed:@"collection"] forState:UIControlStateNormal];
-
- }else{
-
- [weakself.collectionBtn setImage:[UIImage imageNamed:@"NoCollection"] forState:UIControlStateNormal];
-
- }
- } failure:^(NSError *error) {
-
- NSLog(@"%@",error);
- }];
- }
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self.navigationView removeAllLeftButton];
-
- self.navigationView.titleLabel.text = self.titleStr;
-
- self.navigationView.titleLabel.textColor = [UIColor whiteColor];
-
- self.view.backgroundColor = [UIColor whiteColor];
-
- kWeakSelf(self);
- [self.navigationView setNavigationBackgroundColor:[UIColor colorWithHexValue:0x3C915C]];
-
- [self.navigationView addLeftButtonWithImage:[UIImage imageNamed:@"back_white"] clickCallBack:^(UIView *view) {
-
- [weakself.navigationController popViewControllerAnimated:YES];
-
- }];
- UIView *rightView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 40)];
- rightView.backgroundColor = [UIColor colorWithHexValue:0x3C915C];
-
- if ([_index isEqualToString:@"0"]) {
-
- [self.navigationView addRightView:rightView clickCallback:nil];
- }
-
-
- _collectionBtn =[UIButton buttonWithType:UIButtonTypeCustom];
-
- [_collectionBtn setImage:[UIImage imageNamed:@"NoCollection"] forState:UIControlStateNormal];
-
- [_collectionBtn addTarget:self action:@selector(collectionClick:) forControlEvents:UIControlEventTouchUpInside];
-
- [rightView addSubview:_collectionBtn];
-
- [_collectionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.size.mas_equalTo(CGSizeMake(40, 40));
- make.left.equalTo(rightView.mas_left).offset(15);
- make.top.equalTo(rightView.mas_top);
- }];
- _shareBtn =[UIButton buttonWithType:UIButtonTypeCustom];
-
- [_shareBtn setImage:[UIImage imageNamed:@"share"] forState:UIControlStateNormal];
- [_shareBtn addTarget:self action:@selector(shareClick:) forControlEvents:UIControlEventTouchUpInside];
-
- [rightView addSubview:_shareBtn];
- [_shareBtn mas_makeConstraints:^(MASConstraintMaker *make) {
-
- make.size.mas_equalTo(CGSizeMake(40, 40));
- make.left.equalTo(_collectionBtn.mas_right).offset(5);
- make.top.equalTo(rightView.mas_top);
- }];
-
- if ([_index isEqualToString:@"1"]) {
-
- self.webView = [[ZLCWebView alloc] initWithFrame:CGRectMake(0,isFullScreen?40:30, kGScreenWidth,isFullScreen?kGScreenHeight-40:kGScreenHeight-30)];
-
- }else{
-
- self.webView = [[ZLCWebView alloc] initWithFrame:CGRectMake(0,isFullScreen? NaviHeight -70:IS_IPHONE_4_OR_LESS? NaviHeight -55 :NaviHeight -60, kGScreenWidth,isFullScreen? kGScreenHeight- NaviHeight+70 :IS_IPHONE_4_OR_LESS? kGScreenHeight- NaviHeight+55: kGScreenHeight- NaviHeight+60)];
-
- }
- if (@available(iOS 11.0, *)) {
-
- self.webView.wkWebView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- }else {
-
- self.automaticallyAdjustsScrollViewInsets = NO;
-
- }
- self.webView.delegate = self;
-
- [self.view addSubview:self.webView];
-
- [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.urlStr]]];
-
- self.webView.wkWebView.scrollView.backgroundColor = [UIColor whiteColor];
- self.webView.wkWebView.scrollView.showsVerticalScrollIndicator = NO;
- // self.webView.wkWebView.scrollView.showsHorizontalScrollIndicator = NO;
- _webView.wkWebView.scrollView.bounces = NO;
- // Do any additional setup after loading the view.
- }
- -(void)collectionClick:(UIButton *)sender{
-
- if (!IsStrEmpty([DKGlobal sharedInstance].token)) {
-
- kWeakSelf(self);
-
- if (![weakself.collectionStaus isEqualToString:@"0"]) {
-
- NSMutableDictionary *parma = [NSMutableDictionary dictionary];
-
- parma[@"id"] = weakself.newsId;
-
- if ([_typeStr isEqualToString:@"2"]) {
-
- parma[@"collectType"] = @"2";
-
- }else{
-
- parma[@"collectType"] = @"0";
-
- }
- self.sessionManager = [[HttpRequestManger alloc]init];
-
- [self.sessionManager sendPostHttpRequestWithUrl:cancelCollection params:parma bodyBlock:nil progress:nil success:^(NSDictionary *response) {
-
- [MBProgressHUD showSuccess:@"取消收藏"];
-
- weakself.collectionStaus = @"0";
-
- [weakself.collectionBtn setImage:[UIImage imageNamed:@"NoCollection"] forState:UIControlStateNormal];
-
-
-
- } failure:^(NSError *error) {
-
- NSLog(@"%@",error);
- }];
- }else{
- kWeakSelf(self);
- NSMutableDictionary *parma = [NSMutableDictionary dictionary];
-
- parma[@"id"] = weakself.newsId;
- if ([_typeStr isEqualToString:@"2"]) {
- parma[@"type"] = @"2";
- }else{
-
- parma[@"type"] = @"0";
- }
-
-
-
- self.sessionManager = [[HttpRequestManger alloc]init];
-
- [self.sessionManager sendPostHttpRequestWithUrl:collectionNews params:parma bodyBlock:nil progress:nil success:^(NSDictionary *response) {
- [MBProgressHUD showSuccess:@"收藏成功"];
-
- weakself.collectionStaus = @"1";
-
- [weakself.collectionBtn setImage:[UIImage imageNamed:@"collection"] forState:UIControlStateNormal];
-
-
- } failure:^(NSError *error) {
- NSLog(@"%@",error);
- }];
- }
- }else{
- [MBProgressHUD showError:@"请先登录"];
- logInViewController *loginVC = [[logInViewController alloc]init];
- [self.navigationController pushViewController:loginVC animated:YES];
-
-
- }
-
-
- }
- - (void)zlcwebViewDidStartLoad:(ZLCWebView *)webview
- {
-
- NSString *requestString = webview.wkWebView.URL.absoluteString;
-
- if ([requestString containsString:@"activity://"]) {
-
- NSString *projectID = [requestString stringByReplacingOccurrencesOfString:@"activity://"withString:@""];
- NSLog(@"projectID=%@",projectID);
- activityDetailVController *activityDetail = [[activityDetailVController alloc]init];
- activityDetail.newsId = projectID;
- activityDetail.titleStr = @"活动详情";
- activityDetail.shareTitle =@"活动详情";
- activityDetail.index =@"0";
- activityDetail.urlStr = [NSString stringWithFormat:@"%@/applyDetail?id=%@&move=ios",baseH5,projectID];
- activityDetail.shareUrl = [NSString stringWithFormat:@"%@/applyDetail?id=%@",baseH5,projectID];
- [self.navigationController pushViewController:activityDetail animated:YES];
-
- }
- [SVProgressHUD show];
- }
- - (void)zlcwebView:(ZLCWebView *)webview shouldStartLoadWithURL:(NSURL *)URL
- {
- NSLog(@"截取到URL:%@",URL);
- }
- - (void)zlcwebView:(ZLCWebView *)webview didFinishLoadingURL:(NSURL *)URL
- {
- [SVProgressHUD dismiss];
-
- NSLog(@"页面加载完成%@",URL);
- }
- - (void)zlcwebView:(ZLCWebView *)webview didFailToLoadURL:(NSURL *)URL error:(NSError *)error
- {
-
- [SVProgressHUD dismiss];
- NSLog(@"加载出现错误");
- }
- //}
- -(void)viewWillDisappear:(BOOL)animated{
-
- [super viewWillDisappear:YES];
-
- _webView = nil;
-
- [self cleanCacheAndCookie];
-
- }
- /**清除缓存和cookie*/
- - (void)cleanCacheAndCookie{
- //清除cookies
- NSHTTPCookie *cookie;
- NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
- for (cookie in [storage cookies]){
- [storage deleteCookie:cookie];
- }
- //清除UIWebView的缓存
- [[NSURLCache sharedURLCache] removeAllCachedResponses];
- NSURLCache * cache = [NSURLCache sharedURLCache];
- [cache removeAllCachedResponses];
- [cache setDiskCapacity:0];
- [cache setMemoryCapacity:0];
- }
- -(void)shareClick:(UIButton *)sender{
- // AppIcon projectItem
- NSArray *arr =@[[UIImage imageNamed:@"AppIcon"]];
-
- if (IsStrEmpty(_shareTitle)) {
-
- _shareTitle = @"";
- }
-
- if (arr) {
- if (IsStrEmpty(self.ImgUrl)){
- self.ImgUrl = @"https://img2018.cnblogs.com/blog/1058389/201812/1058389-20181211200433415-1810829224.png";
- }
-
- NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
- [shareParams SSDKSetupShareParamsByText:@"中经联盟资讯"
- images:self.ImgUrl
- url:[NSURL URLWithString:[NSString stringWithFormat:@"%@",_shareUrl]]
- title:_shareTitle
- type:SSDKContentTypeWebPage];
- // [shareParams SSDKEnableUseClientShare];
-
- // [SSUIShareActionSheetStyle setShareActionSheetStyle:(ShareActionSheetStyle)ShareActionSheetStyleSimple];
- [ShareSDK showShareActionSheet:nil //要显示菜单的视图, iPad版中此参数作为弹出菜单的参照视图,只有传这个才可以弹出我们的分享菜单,可以传分享的按钮对象或者自己创建小的view 对象,iPhone可以传nil不会影响
- items:@[@(SSDKPlatformSubTypeWechatSession),@(SSDKPlatformSubTypeWechatTimeline)]
- shareParams:shareParams
- onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {
-
- switch (platformType) {
- case SSDKPlatformSubTypeWechatSession:
-
- break;
- case SSDKPlatformSubTypeWechatTimeline:
-
- break;
- default:
- break;
- }
-
- switch (state) {
- case SSDKResponseStateSuccess:
- // {
- // UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享成功"
- // message:nil
- // delegate:nil
- // cancelButtonTitle:@"确定"
- // otherButtonTitles:nil];
- // [alertView show];
- break;
- // }
- case SSDKResponseStateFail:
- // {
- // UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"分享失败"
- // message:nil
- // delegate:nil
- // cancelButtonTitle:@"OK"
- // otherButtonTitles:nil, nil];
- // [alert show];
- //
- //
- // NSLog(@"%@",error);
- break;
- // }
- default:
- break;
- }
- }
- ];
- }
-
-
-
-
- }
- - (void)dealloc {
- if (_sessionManager) {
- [_sessionManager cancelAllTask];
- }
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- DebugLog(@"%@没有造成循环引用", [self class]);
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #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
|