123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806 |
- //
- // AppDelegate.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/1/16.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "AppDelegate.h"
- #import "LDTabbarController.h"
- #import <AlibcTradeSDK/AlibcTradeSDK.h>
- #import "UMMobClick/MobClick.h"
- #import <Bugly/Bugly.h>
- #import "MiPushSDK.h"
- #import "RouteManager.h"
- #import "LDGuideView.h"
- #import <JLRoutes.h>
- #import <WXApi.h>
- #import "WXApiManager.h"
- #import "LDSearchPopView.h"
- #import "CCAlertShowView.h"
- #import "LDUpdatePopView.h"
- #import "LDGoodListViewController.h"
- #import "LDAdWebViewController.h"
- //#import <UMSocialCore/UMSocialCore.h>
- #import "HYUMShareManager.h"
- #import "LDFindSearchResultViewController.h"
- #import "GetScreenImage.h"
- #import "LDScreenshotShareView.h"
- #import "NetworkTool.h"
- #import "PhoneLoginManager.h"
- #import "CreatSearchManager.h"
- #import "LDMyFansViewController.h"
- #import "LDAchievementViewController.h"
- #import "LDChildAccountViewController.h"
- #import "LDCollectionMainViewController.h"
- #import "LDLoginViewController.h"
- #import "WWNetWorkingTool.h"
- #import "KXWKWebViewVC.h"
- #import "KXAdAlertModel.h"
- #import "XHLaunchAd.h"
- #import "LDWebDetailController.h"
- #import "XTGuidePagesViewController.h"
- #import "CALayer+Transition.h"
- #import "LDChildFansModel.h"
- #import "LDSuperInfoVC.h"
- @interface AppDelegate ()
- <
- MiPushSDKDelegate,
- UNUserNotificationCenterDelegate,
- UIApplicationDelegate,
- WXApiDelegate,
- XHLaunchAdDelegate,
- selectDelegate
- >
- @property(nonatomic,strong)LDScreenshotShareView *screenshotShareView;
- @property(nonatomic,strong)NSMutableArray *dataArray;;
- @end
- @implementation AppDelegate
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
- // Override point for customization after application launch.
-
-
- [self checkNetWorkState]; //监听网络并注册百川sdk
- [self setUpWeChat]; //微信sdk
- [self setDefauleSex]; //设置默认性别
- [self setUpSVProgressHUD]; //设置loading指示器
- [self setBugly]; //设置bugly
- [self setUMAnalisis]; //设置友盟统计
- [self setUMShareAndWeChartInfo]; //设置友盟分享和微信appkey和秘钥
- [self addGuidepage]; //首次安装显示引导页
- [self setupMiPush]; //小米推送
- [self cancelIconBadgeNumber]; //处理角标
- [self addRouteManager]; //初始化路由跳转
- [LDDeviceTools addOpenNumber]; //增加APP打开次数
- [LDDeviceTools addOpenLoginAgreeNumber];
- [self getRemoteNotificationDictWithDict:launchOptions]; //设置点击推送跳转
- [self loadPhoneLogInButton];
-
-
- return YES;
- }
- #pragma mark---
- -(void)openNoticeclick
- {
-
- }
- -(void)noNotificationPermission
- {
- LDnoticeView *noticeV =[[LDnoticeView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
- [self.window addSubview:noticeV];
- }
- - (void)checkNetWorkState {
- //创建网络监听管理者对象
- AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
-
- //设置监听
- __weak typeof(manager) weakManager = manager;
- [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
-
-
- BOOL isReachable = (status == AFNetworkReachabilityStatusReachableViaWiFi
- || status == AFNetworkReachabilityStatusReachableViaWWAN);
- if (isReachable) {
- NSLog(@"啊啊啊啊啊啊啊啊啊,有网络诶!!!!");
- [self setupAlibcSDK];
- [weakManager stopMonitoring];
- }
- }];
- //开始监听
- [manager startMonitoring];
-
- }
- -(void)addGuidepage
- {
- // 测试的时候改变info 里的版本号就可以了
- NSArray *images = @[@"ydy_back", @"ydy_back", @"ydy_back"];
- BOOL y = [XTGuidePagesViewController isShow];
-
- if (y) {
-
- XTGuidePagesViewController *xt = [[XTGuidePagesViewController alloc] init];
- self.window.rootViewController = xt;
- xt.delegate = self;
- [xt guidePageControllerWithImages:images AndTitle:@[@"先领券,再购物",@"购物下单有返现",@"邀请好友赚佣金"] Andtipe:@[@"大额优惠券,省钱又省心",@"有券有返现,能省又能赚",@"一键分享,轻松躺赚"]];
- }else{
- [self setupKeyWindow];
- }
- }
- -(void)test{
- // [[GetScreenImage shareInstance] startListening];
-
-
- }
- -(void)clickEnter
- {
- [self setupKeyWindow];
- }
- -(void)setUMWeChat{
- [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:WX_APPID appSecret:WX_APP_SECRET redirectURL:nil];
-
- }
- - (void)setUpWeChat {
- [WXApi registerApp:WX_APPID];
- }
- - (void)setupMiPush {
- [MiPushSDK registerMiPush:self];
- }
- - (void)setBugly {
- [Bugly startWithAppId:BUGLY_ID];
- }
- -(void)setUMAnalisis
- {
- UMConfigInstance.appKey = UMAPP_KEY;
- UMConfigInstance.channelId = @"App Store";
- NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
- NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
- [MobClick setAppVersion:app_Version];
- [MobClick startWithConfigure:UMConfigInstance];
- [MobClick setLogEnabled:YES];
- }
- -(void)setUMShareAndWeChartInfo{
- [[HYUMShareManager shareInstance] setUMShare];
- }
- - (void)cancelIconBadgeNumber {
- // 注册显示应用程序BadgeNumber的通知
- UIApplication *application = [UIApplication sharedApplication];
-
- UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil];
- [application registerUserNotificationSettings:settings];
- if (application.applicationIconBadgeNumber > 0) {
- application.applicationIconBadgeNumber = 0;
- }
- }
- /**
- 设置默认性别
- */
- - (void)setDefauleSex {
- NSString *sex = [[NSUserDefaults standardUserDefaults] objectForKey:UserSexKey];
- if (sex.length == 0 || [sex isEqualToString:@""]) {
- //默认性别为女
- [[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:UserSexKey];
- }
- }
- /**
- 首次安装性别引导
- */
- - (void)firstLaunchingGuide {
-
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- NSString *launched = [userDefaults objectForKey:@"launched"];
- if (!launched)
- {
- [self creatGuideView];
- launched = @"YES";
- [userDefaults setObject:launched forKey:@"launched"];
- [userDefaults synchronize];
- }
- }
- - (void)creatGuideView {
- LDGuideView *guideView = [[LDGuideView alloc] initWithFrame:self.window.bounds];
- [self.window addSubview:guideView];
- }
- /**
- 加载是否显示手机登录
- */
- - (void)loadPhoneLogInButton {
-
- NSString *url = [NSString stringWithFormat:@"%@/api/v2/channel/getDevByChannelId",BaseURL];
- NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
- NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
- NSDictionary *para = @{@"channel_id":Channel_id,
- @"version":app_Version
- };
- [LDHttp get:url params:para success:^(id json) {
- if ([json[@"ios"] boolValue]) {
- //显示
- [PhoneLoginManager shareManager].showPhoneBtn = @(YES);
- }else {
- //隐藏
- [PhoneLoginManager shareManager].showPhoneBtn = @(NO);
- }
-
- } failure:^(NSError *error) {
-
- }];
-
- }
- // 启动广告图
- - (void)addXHAdvert {
- [WWNetWorkingTool sharedNetWorkTool];
- //设置你工程的启动页使用的是:LaunchImage 还是 LaunchScreen.storyboard(不设置默认:LaunchImage)
- [XHLaunchAd setLaunchSourceType:SourceTypeLaunchImage];
-
- //1.因为数据请求是异步的,请在数据请求前,调用下面方法配置数据等待时间.
- //2.设为3即表示:启动页将停留3s等待服务器返回广告数据,3s内等到广告数据,将正常显示广告,否则将不显示
- //3.数据获取成功,配置广告数据后,自动结束等待,显示广告
- //注意:请求广告数据前,必须设置此属性,否则会先进入window的的根控制器
- [XHLaunchAd setWaitDataDuration:2];
-
- //广告数据请求
- [[WWNetWorkingTool sharedNetWorkTool] post:[NSString stringWithFormat:@"%@/Advert/V1/getAdvert",advURL] parameter:@{@"space_sign" : @"24"} success:^(id responseObject) {
- NSNumber *code = responseObject[@"code"];
- if ([code isEqual:0]) {
- //
- }
- //广告数据转模型
- self.dataArray = [KXAdAlertModel mj_objectArrayWithKeyValuesArray:responseObject[@"res"]];
-
- if (self.dataArray.count<1) {
- return;
- }
- KXAdAlertModel *model = self.dataArray.firstObject;
- //配置广告数据
- XHLaunchImageAdConfiguration *imageAdconfiguration = [XHLaunchImageAdConfiguration defaultConfiguration];
- imageAdconfiguration.duration = 3;
- imageAdconfiguration.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-Fitsize(115));
- if (iPhoneX) {
- imageAdconfiguration.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-162);
- }
- //广告图片URLString/或本地图片名(.jpg/.gif请带上后缀)
- imageAdconfiguration.imageNameOrURLString = model.img_url;
- //广告点击打开页面参数(openModel可为NSString,模型,字典等任意类型)
- imageAdconfiguration.openModel = model.advert_url;
- //后台返回时,是否显示广告
- imageAdconfiguration.showEnterForeground = NO;
-
- //添加子视图
- UIView *bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height-Fitsize(115), [UIScreen mainScreen].bounds.size.width, Fitsize(115))];
- bottomView.backgroundColor = [UIColor whiteColor];
-
- NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
- NSString *icon = [[infoDictionary valueForKeyPath:@"CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles"] lastObject];
- UIImageView *appIconImg = [[UIImageView alloc]initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/2 - 25, 15, 50, 50)];
- appIconImg.image = [UIImage imageNamed:icon];
- appIconImg.layer.masksToBounds = YES;
- appIconImg.layer.cornerRadius = 5;
- [bottomView addSubview:appIconImg];
-
- UILabel *appNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 80, [UIScreen mainScreen].bounds.size.width, 20)];
- appNameLabel.text = infoDictionary[@"CFBundleDisplayName"];
- appNameLabel.font = [UIFont systemFontOfSize:16];
- appNameLabel.textColor = [UIColor darkGrayColor];
- appNameLabel.textAlignment = NSTextAlignmentCenter;
- [bottomView addSubview:appNameLabel];
- // imageAdconfiguration.subViews = @[bottomView];
-
- //显示开屏广告
- [XHLaunchAd imageAdWithImageAdConfiguration:imageAdconfiguration delegate:self];
- } faliure:^(id error) {
- //
- }];
- }
- /**
- 广告点击事件代理方法
- */
- -(void)xhLaunchAd:(XHLaunchAd *)launchAd clickAndOpenModel:(id)openModel clickPoint:(CGPoint)clickPoint{
- NSLog(@"广告点击事件");
- /** openModel即配置广告数据设置的点击广告时打开页面参数(configuration.openModel) */
- if (openModel == nil) {
- return;
- }
-
- //异步发送广告记录
- dispatch_async(dispatch_get_global_queue(0, 0), ^{
- KXAdAlertModel *model = self.dataArray.firstObject;
- [[WWNetWorkingTool sharedNetWorkTool] post:[NSString stringWithFormat:@"%@/api/Advert/V1/advertRecord",advURL] parameter:@{@"space_sign" : @"24", @"advert_id" : model.ID} success:^(id responseObject) {
- //
- NSLog(@"%@", responseObject);
- } faliure:^(id error) {
- //
- }];
- });
-
-
- NSString *urlString = (NSString *)openModel;
- UIViewController *rootViewController = self.window.rootViewController;
- LDWebDetailController *webVC = [[LDWebDetailController alloc]init];
- webVC.url = urlString;
- NSArray *childsVC = [rootViewController childViewControllers];
- UINavigationController *navVC = childsVC.firstObject;
- [navVC pushViewController:webVC animated:YES];
- }
- /**
- 配置阿里百川SDK
- */
- - (void)setupAlibcSDK {
- // 百川平台基础SDK初始化,加载并初始化各个业务能力插件
- [[AlibcTradeSDK sharedInstance] asyncInitWithSuccess:^{
-
- } failure:^(NSError *error) {
- NSLog(@"Init failed: %@", error.description);
- }];
-
- // 开发阶段打开日志开关,方便排查错误信息
- //默认调试模式打开日志,release关闭,可以不调用下面的函数
- // [[AlibcTradeSDK sharedInstance] setDebugLogOpen:YES];
-
- // 配置全局的淘客参数
- //如果没有阿里妈妈的淘客账号,setTaokeParams函数需要调用
- AlibcTradeTaokeParams *taokeParams = [[AlibcTradeTaokeParams alloc] init];
- taokeParams.pid = ALTK_PID; //mm_XXXXX为你自己申请的阿里妈妈淘客pid
- [[AlibcTradeSDK sharedInstance] setTaokeParams:taokeParams];
-
- //设置全局的app标识,在电商模块里等同于isv_code
- //没有申请过isv_code的接入方,默认不需要调用该函数
- [[AlibcTradeSDK sharedInstance] setISVCode:@"your_isv_code"];
-
- // 设置全局配置,是否强制使用h5
- // [[AlibcTradeSDK sharedInstance] setIsForceH5:NO];
- }
- - (void)setupKeyWindow {
- self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
- LDTabbarController *tab = [[LDTabbarController alloc] init];
- self.window.rootViewController = tab;
- self.window.backgroundColor = [UIColor whiteColor];
- [self.window makeKeyAndVisible];
- }
- - (void)setUpSVProgressHUD {
- [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
- [SVProgressHUD setForegroundColor:[UIColor YHColorWithHex:0xff2420]];
- [SVProgressHUD setBackgroundColor:[UIColor YHColorWithHex:0xf5f4f4]];
- [SVProgressHUD setMinimumDismissTimeInterval:2];
- }
- - (void)addRouteManager {
- // [RouteManager registerRouteWithScheme:SchemeKey];
- }
- /**
- 点击通知跳转到指定页面
- */
- - (void)getRemoteNotificationDictWithDict:(NSDictionary *)tfdic {
- NSDictionary *remoteNotification = [tfdic objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
- if(remoteNotification){
- NSString *messageId;
- if ([remoteNotification containsObjectForKey:@"_id_"]) {
- messageId = [remoteNotification objectForKey:@"_id_"];
- }
- if (messageId!=nil) {
- [MiPushSDK openAppNotify:messageId];
- }
- }
- [self jumpViewController:remoteNotification];
- }
- - (void)jumpViewController:(NSDictionary *)remoteNotification {
-
- NSInteger pushType = [remoteNotification[@"pushType"] integerValue];
-
- switch (pushType) {
- case 1000:
- {
- LDEventModel *evevtModel = [[LDEventModel alloc] initWithOrigin:@"0" category_id:@"0" source:pushAction];
- LDGoodDetailViewController *detail = [[LDGoodDetailViewController alloc] init];
- if ([remoteNotification.allKeys containsObject:@"goods_id"]) {
- DetailRequestModel *requestModel = [DetailRequestModel yy_modelWithJSON:remoteNotification];
- detail.requestModel = requestModel;
- }
- detail.eventModel = evevtModel;
- [[self currentViewController].navigationController pushViewController:detail animated:YES];
- }
-
- break;
- case 1001:
- {
- //列表
- LDGoodListViewController *list = [[LDGoodListViewController alloc] init];
- if ([remoteNotification.allKeys containsObject:@"gid"]) {
- list.cate_id = remoteNotification[@"gid"];
- }else {
- list.cate_id = @"";
- }
- if ([remoteNotification.allKeys containsObject:@"name"]) {
- list.name = remoteNotification[@"name"];
- }else {
- list.name = @"";
- }
- list.topRequest = 2;
- [[self currentViewController].navigationController pushViewController:list animated:YES];
- }
- break;
- case 1002:
- {
- LDAdWebViewController *web = [[LDAdWebViewController alloc] init];
- if ([remoteNotification.allKeys containsObject:@"url"]) {
- web.url = remoteNotification[@"url"];
- }else {
- web.url = @"";
- }
- //h5
- [[self currentViewController].navigationController pushViewController:web animated:YES];
- }
-
- break;
- case 1003:
- {
- //我的好友
- if (![AccountTool isLogin]) {
- [self goToLoginPage];
- return;
- }
- LDMyFansViewController *collection = [[LDMyFansViewController alloc] init];
- [[self currentViewController].navigationController pushViewController:collection animated:YES];
- }
-
- break;
- case 1004:
- {
- //我的收益
- if (![AccountTool isLogin]) {
- [self goToLoginPage];
- return;
- }
- LDAchievementViewController *collection = [[LDAchievementViewController alloc] init];
- [[self currentViewController].navigationController pushViewController:collection animated:YES];
- }
- break;
- case 1005:
- {
- //我的账户
- if (![AccountTool isLogin]) {
- [self goToLoginPage];
- return;
- }
- LDChildAccountViewController *collection = [[LDChildAccountViewController alloc] init];
- [[self currentViewController].navigationController pushViewController:collection animated:YES];
- }
- break;
- case 1006:
- {
- //收藏
- if (![AccountTool isLogin]) {
- [self goToLoginPage];
- return;
- }
- LDCollectionMainViewController *collection = [[LDCollectionMainViewController alloc] init];
- [[self currentViewController].navigationController pushViewController:collection animated:YES];
- }
- break;
- case 1010:
- {
- UITabBarController *tabbar = (UITabBarController *)[UIApplication sharedApplication].keyWindow.rootViewController;
- tabbar.selectedIndex = tabbar.childViewControllers.count-1;
-
- }
- break;
- case 1011:
- {
- LDChildFansModel *model = [[LDChildFansModel alloc] init];
- model.user_id = remoteNotification[@"user_id"];
- LDSuperInfoVC *infoVc = [[LDSuperInfoVC alloc] init];
- infoVc.fansmodel = model;
- [[self currentViewController].navigationController pushViewController:infoVc animated:YES];
- }
- break;
- default:
- break;
- }
-
-
- }
- - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
- [[UMSocialManager defaultManager] handleOpenURL:url sourceApplication:sourceApplication annotation:annotation];
-
- // 新接口写法
- if (![[AlibcTradeSDK sharedInstance] application:application
- openURL:url
- sourceApplication:sourceApplication
- annotation:annotation]) {
- // 处理其他app跳转到自己的app
-
- }
- return YES;
- }
- // ios9 新api
- - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {
- //微信分享
- [[UMSocialManager defaultManager] handleOpenURL:url options:options];
-
- NSString *urlStr = url.absoluteString;
- if ([urlStr hasPrefix:@"liedou"]) {
- NSArray *params = [[url absoluteString] componentsSeparatedByString:@"?"];
- NSString *pageType;
- if (params.count > 0) {
- pageType = params.firstObject;
- }
- if ([pageType containsString:@"detail"]) {
- LDGoodDetailViewController *detail = [[LDGoodDetailViewController alloc] init];
- DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithUrlQueryString:[url query]];
- detail.requestModel = requestModel;
- [[self currentViewController].navigationController pushViewController:detail animated:YES];
- }
- }
-
- // 新接口写法
- if (@available(iOS 9.0, *)) {
- if (![[AlibcTradeSDK sharedInstance] application:application
- openURL:url
- options:options]) {
- //处理其他app跳转到自己的app,如果百川处理过会返回YES
- }
- } else {
- // Fallback on earlier versions
- }
- return YES;
- }
- #pragma mark 注册push服务.
- - (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
- {
-
- // 注册APNS成功, 注册deviceToken
- [MiPushSDK bindDeviceToken:deviceToken];
-
- }
- - (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err
- {
- NSLog(@"APNS error: %@", err);
-
- // 注册APNS失败.
- // 自行处理.
- }
- #pragma mark MiPushSDKDelegate
- - (void)miPushRequestSuccWithSelector:(NSString *)selector data:(NSDictionary *)data
- {
- // 请求成功
- // 可在此获取regId
- if ([selector isEqualToString:@"bindDeviceToken:"]) {
- NSLog(@"regid = %@", data[@"regid"]);
- }
- }
- - (void)miPushRequestErrWithSelector:(NSString *)selector error:(int)error data:(NSDictionary *)data
- {
- // 请求失败
- }
- #pragma mark Local And Push Notification
- - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
- {
- NSLog(@"APNS notify: %@", userInfo);
-
- // 当同时启动APNs与内部长连接时, 把两处收到的消息合并. 通过miPushReceiveNotification返回
- [MiPushSDK handleReceiveRemoteNotification:userInfo];
- }
- // iOS10新加入的回调方法
- // 应用在前台收到通知
- - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler __IOS_AVAILABLE(10.0) {
- NSDictionary * userInfo = notification.request.content.userInfo;
- if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
- NSLog(@"APNS notify: %@", userInfo);;
- [MiPushSDK handleReceiveRemoteNotification:userInfo];
- NSString *messageId = [userInfo objectForKey:@"_id_"];
- [MiPushSDK openAppNotify:messageId];
- }
-
- [self cancelIconBadgeNumber];
-
- }
- // 点击通知进入应用
- - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler __IOS_AVAILABLE(10.0) {
-
- NSDictionary * userInfo = response.notification.request.content.userInfo;
- if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
- NSLog(@"APNS notify: %@", userInfo);
- [MiPushSDK handleReceiveRemoteNotification:userInfo];
- NSString *messageId = [userInfo objectForKey:@"_id_"];
- [MiPushSDK openAppNotify:messageId];
- }
-
- [self jumpViewController:userInfo];
- completionHandler();
- }
- #pragma mark MiPushSDKDelegate
- - (void)applicationWillResignActive:(UIApplication *)application {
- // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
- // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
- }
- - (void)applicationDidEnterBackground:(UIApplication *)application {
- // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
- // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
- [SVProgressHUD dismiss];
- [self cancelIconBadgeNumber];
- }
- - (void)applicationWillEnterForeground:(UIApplication *)application {
- // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
- }
- - (void)applicationDidBecomeActive:(UIApplication *)application {
- BOOL y = [XTGuidePagesViewController isShow];
- if (!y) {//是否需要显示引导页
- [self checkPasteboardText]; //识别剪贴板
- }
- //判断是否开启通知
- [[NSNotificationCenter defaultCenter] postNotificationName:@"setMessage" object:nil];
- }
- - (void)applicationWillTerminate:(UIApplication *)application {
- // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
- }
- #pragma mark ----
- - (void)checkPasteboardText {
-
- BOOL y = [XTGuidePagesViewController isShow];
- if (y){
- return;
- }
- UIAlertController *alert =(UIAlertController *)[self getActivityViewController:@"UIAlertController"];
- if (alert != nil) {
- [[UIApplication sharedApplication].keyWindow.rootViewController dismissViewControllerAnimated:YES completion:nil];
- }
-
-
- UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
- NSString *pasteText = pasteBoard.string;
-
- if (pasteText.length > 0 && [self isNum:pasteText]) {
- return;
- }
-
- if (pasteText.length >= 8) {
- LDSearchPopView *popView = [[LDSearchPopView alloc] initWithFrame:CGRectMake(0, 0, Fitsize(310), Fitsize(246)) searchText:pasteText];
- CCAlertShowView *showView = [CCAlertShowView showAlertViewWithView:popView backgroundDismissEnable:YES];
- popView.cancelClick = ^{
- [showView dismiss];
- };
-
- popView.searchlClick = ^{
- // LDFindSearchResultViewController *result = [[LDFindSearchResultViewController alloc] init];
- // result.searchName = pasteText;
- // result.hiddenNavigationWhenPop = YES;
- // [[self currentViewController].navigationController pushViewController:result animated:YES];
- CreatSearchManager *manager = [[CreatSearchManager alloc] init];
- [manager createSearchViewControllerWith:pasteText viewController:[self currentViewController]];
- [showView dismiss];
- [MobClick event:popCopySearch];
- };
- pasteBoard.string = @"";
- }
-
-
- }
- - (UIViewController *)currentViewController{
-
- UIViewController * currVC = nil;
- UIWindow *window = [UIApplication sharedApplication].delegate.window;
- UIViewController * Rootvc = window.rootViewController;
-
- do {
- if ([Rootvc isKindOfClass:[UINavigationController class]]) {
- UINavigationController * nav = (UINavigationController *)Rootvc;
- UIViewController * v = [nav.viewControllers lastObject];
- currVC = v;
- Rootvc = v.presentedViewController;
- continue;
- }else if([Rootvc isKindOfClass:[UITabBarController class]]){
- UITabBarController * tabVC = (UITabBarController *)Rootvc;
- currVC = tabVC;
- Rootvc = [tabVC.viewControllers objectAtIndex:tabVC.selectedIndex];
- continue;
- }
- } while (Rootvc!=nil);
-
- return currVC;
- }
- - (void)goToLoginPage {
- LDNewLoginVC *login = [[LDNewLoginVC alloc] init];
- login.modalPresentationStyle = UIModalPresentationFullScreen;
- [[self currentViewController] presentViewController:login animated:YES completion:nil];
- }
- - (NSMutableArray *)dataArray {
- if (!_dataArray) {
- _dataArray = [NSMutableArray array];
- }
- return _dataArray;
- }
- /**
- 识别是否为纯数字
- */
- - (BOOL)isNum:(NSString *)checkedNumString {
- checkedNumString = [checkedNumString stringByTrimmingCharactersInSet:[NSCharacterSet decimalDigitCharacterSet]];
- if(checkedNumString.length > 0) {
- return NO;
- }
- return YES;
- }
- - (UIViewController *)getActivityViewController:(NSString *)controllerName {
-
- UIViewController *topVC = [UIApplication sharedApplication].keyWindow.rootViewController;
-
- while (topVC.presentedViewController) {
-
- topVC = topVC.presentedViewController;
- if ([[topVC.class description]isEqualToString:controllerName]) {
- return topVC;
- }
-
-
- }
-
- return nil;
-
- }
- @end
|