271 lines
8.9 KiB
Objective-C
271 lines
8.9 KiB
Objective-C
//
|
|
// ViewController.m
|
|
// Ifish
|
|
//
|
|
// Created by imac on 15/9/27.
|
|
// Copyright © 2015年 imac. All rights reserved.
|
|
//
|
|
|
|
#import "ViewController.h"
|
|
|
|
#import "AFNetworking.h"
|
|
#import "DisconnectNetController.h"
|
|
#import "MMProgressHUD.h"
|
|
#import "MMProgressHUDOverlayView.h"
|
|
#import "NSObject+LBLaunchImage.h"
|
|
#import "IfishLoadingWebViewController.h"
|
|
#import "IfishMianTabViewController.h"
|
|
#import "IfishAlibcWebViewController.h"
|
|
#import <AlibcTradeSDK/AlibcTradeSDK.h>
|
|
@interface ViewController ()<UIAlertViewDelegate>
|
|
|
|
@property(nonatomic)UIActivityIndicatorView*indicatorView;
|
|
@property(nonatomic,strong) UIImageView *backImg;
|
|
@property(nonatomic,strong) NSString *adUrl;
|
|
@property(nonatomic,strong) NSString *imgUrl;
|
|
|
|
@end
|
|
|
|
@implementation ViewController
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
self.view.backgroundColor = [UIColor whiteColor];
|
|
|
|
self.backImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ifish_loading_hold"]];
|
|
self.backImg.frame = CGRectMake(0,0,kScreenSize.width,kScreenSize.height);
|
|
self.backImg.contentMode = UIViewContentModeScaleAspectFill;
|
|
[self.view addSubview:self.backImg];
|
|
|
|
_indicatorView=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
|
|
_indicatorView.center=CGPointMake(kScreenSize.width/2, kScreenSize.height/2);
|
|
|
|
//[self.view addSubview:_indicatorView];
|
|
[self testNetStatusByAF];
|
|
|
|
}
|
|
|
|
-(void)loadADdata
|
|
{
|
|
__weak typeof (self)weakSelf = self;
|
|
[AFHttpTool getIfishBannerData:IfishAdTypeLoadAD success:^(id response) {
|
|
NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
|
|
NSString *result=reDic[@"result"];
|
|
if ([result isEqualToString:@"100"]) {
|
|
NSArray *data= reDic[@"data"];
|
|
for (NSDictionary *dic in data) {
|
|
IfishBannerData *bannerdata = [[IfishBannerData alloc] initWithDict:dic];
|
|
weakSelf.imgUrl = bannerdata.adImage;
|
|
weakSelf.adUrl = bannerdata.adLink;
|
|
|
|
}
|
|
|
|
[weakSelf startLounchImg];
|
|
|
|
}else{
|
|
|
|
//[weakSelf.view makeToast:@"广告位获取失败"];
|
|
}
|
|
|
|
[_indicatorView stopAnimating];
|
|
} failure:^(NSError *err) {
|
|
[_indicatorView stopAnimating];
|
|
DisconnectNetController *connectVC =[[DisconnectNetController alloc] init];
|
|
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:connectVC];
|
|
[nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault];
|
|
[UIApplication sharedApplication].delegate.window.rootViewController=nav;
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
-(void)startLounchImg{
|
|
|
|
__weak typeof(self)weakSelf = self;
|
|
[NSObject makeLBLaunchImageAdView:^(LBLaunchImageAdView *imgAdView) {
|
|
[weakSelf.view addSubview:imgAdView];
|
|
|
|
//设置广告的类型
|
|
imgAdView.getLBlaunchImageAdViewType(LogoAdType);
|
|
//设置本地启动图片
|
|
//imgAdView.localAdImgName = @"Ifishlaunch_adView.jpg";
|
|
imgAdView.imgUrl = self.imgUrl;
|
|
//自定义跳过按钮
|
|
imgAdView.skipBtn.backgroundColor = [UIColor blackColor];
|
|
//各种点击事件的回调
|
|
imgAdView.clickBlock = ^(clickType type){
|
|
switch (type) {
|
|
case clickAdType:{
|
|
NSLog(@"点击广告回调");
|
|
if (![weakSelf.adUrl isKindOfClass:[NSNull class]] && weakSelf.adUrl &&![weakSelf.adUrl isEqualToString:@""]){
|
|
|
|
//字条串是否包含有某字符串
|
|
if ([weakSelf.adUrl rangeOfString:@"taobao"].location == NSNotFound) {
|
|
|
|
IfishLoadingWebViewController *pushVC = [[IfishLoadingWebViewController alloc] init];
|
|
pushVC.pushlink = weakSelf.adUrl;
|
|
[ weakSelf presentViewController:pushVC animated:YES completion:^{
|
|
|
|
}];
|
|
|
|
}else {
|
|
|
|
[weakSelf tapTtemListAt:weakSelf.adUrl];
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
break;
|
|
case skipAdType:
|
|
{
|
|
NSLog(@"点击跳过回调");
|
|
[weakSelf setAppTabRoot];
|
|
}
|
|
|
|
break;
|
|
case overtimeAdType:
|
|
|
|
{
|
|
|
|
NSLog(@"倒计时完成后的回调");
|
|
[weakSelf setAppTabRoot];
|
|
}
|
|
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
};
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
#pragma mark - 商品列表点击事件
|
|
// 宝贝详情页面
|
|
-(void)tapTtemListAt:(NSString *)goodslink
|
|
{
|
|
//535991514644
|
|
//id<AlibcTradePage> page = [AlibcTradePageFactory itemDetailPage: @"535991514644"];
|
|
//根据链接打开页面
|
|
id<AlibcTradePage> page = [AlibcTradePageFactory page:goodslink];
|
|
AlibcTradeShowParams* showParam = [[AlibcTradeShowParams alloc] init];
|
|
showParam.openType = AlibcOpenTypeH5;
|
|
|
|
//自定义web
|
|
IfishAlibcWebViewController* myView = [[IfishAlibcWebViewController alloc] init];
|
|
NSInteger ret = [[AlibcTradeSDK sharedInstance].tradeService show:self.navigationController webView:myView.webView page:page showParams:showParam taoKeParams:nil trackParam:nil tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) {
|
|
|
|
} tradeProcessFailedCallback:^(NSError * _Nullable error) {
|
|
|
|
}]; //返回1,说明h5打开,否则不应该展示页面
|
|
if (ret == 1) {
|
|
|
|
self.hidesBottomBarWhenPushed = YES;
|
|
[self.navigationController pushViewController:myView animated:YES];
|
|
//[self presentViewController:myView animated:YES completion:^{
|
|
|
|
//}];
|
|
}
|
|
}
|
|
|
|
//设置根视图
|
|
-(void)setAppTabRoot{
|
|
|
|
IfishMianTabViewController *mianVC=[[IfishMianTabViewController alloc] init];
|
|
[UIApplication sharedApplication].delegate.window.rootViewController=mianVC;
|
|
|
|
}
|
|
|
|
-(void)viewWillAppear:(BOOL)animated{
|
|
|
|
[_indicatorView startAnimating];
|
|
// [self initMMProgressHUD];
|
|
|
|
}
|
|
-(void)viewWillDisappear:(BOOL)animated{
|
|
[_indicatorView stopAnimating];
|
|
//[self mmPogressHUDdismiss];
|
|
|
|
}
|
|
- (void)didReceiveMemoryWarning {
|
|
|
|
[super didReceiveMemoryWarning];
|
|
// Dispose of any resources that can be recreated.
|
|
|
|
}
|
|
-(void)testNetStatusByAF{
|
|
|
|
[[AFNetworkReachabilityManager sharedManager] startMonitoring];
|
|
[[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
|
|
NSLog(@"%ld", (long)status);
|
|
switch (status) {
|
|
case AFNetworkReachabilityStatusUnknown:
|
|
NSLog(@"未知");
|
|
break;
|
|
case AFNetworkReachabilityStatusNotReachable:
|
|
[_indicatorView stopAnimating];
|
|
NSLog(@"无连接");
|
|
[self showViewOfNoNet];
|
|
|
|
break;
|
|
case AFNetworkReachabilityStatusReachableViaWWAN:
|
|
|
|
|
|
NSLog(@"2/3G");
|
|
break;
|
|
case AFNetworkReachabilityStatusReachableViaWiFi:
|
|
|
|
NSLog(@"Wifi");
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}];
|
|
|
|
}
|
|
-(void)showViewOfNoNet{
|
|
|
|
DisconnectNetController*disconectvc=[[DisconnectNetController alloc]init];
|
|
|
|
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:disconectvc];
|
|
[nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault];
|
|
//self.window.rootViewController=nav;
|
|
[self presentViewController:nav animated:YES completion:nil];
|
|
|
|
}
|
|
-(void)initMMProgressHUD{
|
|
|
|
NSMutableArray *images = [[NSMutableArray alloc] init];
|
|
|
|
for (int i = 1; i <= 63; i ++) {
|
|
|
|
if (i < 10) {
|
|
[images addObject:[UIImage imageNamed:[NSString stringWithFormat:@"neves000%d",i]]];
|
|
|
|
}else{
|
|
[images addObject:[UIImage imageNamed:[NSString stringWithFormat:@"neves00%d",i]]];
|
|
}
|
|
|
|
}
|
|
|
|
//_autodismiss = YES;//MMProgressHUDWindowOverlayModeLinear
|
|
|
|
[MMProgressHUD setPresentationStyle:MMProgressHUDPresentationStyleNone];
|
|
|
|
/**
|
|
* status: Custom Animated Image
|
|
*/
|
|
[MMProgressHUD showWithTitle:@"" status:@"" images:images];
|
|
|
|
}
|
|
|
|
-(void)mmPogressHUDdismiss{
|
|
|
|
[MMProgressHUD dismissWithSuccess:@""];
|
|
|
|
}
|
|
|
|
@end
|