线上所有马甲包模板,与《猎豆》同UI。域名zhuadd

AppDelegate.m 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. //
  2. // AppDelegate.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/1/16.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "AppDelegate.h"
  9. #import "HSQTabbarController.h"
  10. #import <AlibcTradeSDK/AlibcTradeSDK.h>
  11. #import "UMMobClick/MobClick.h"
  12. #import <Bugly/Bugly.h>
  13. #import "MiPushSDK.h"
  14. #import "RouteManager.h"
  15. #import "HSQGuideView.h"
  16. #import <JLRoutes.h>
  17. #import <WXApi.h>
  18. #import "WXApiManager.h"
  19. #import "HSQSearchPopView.h"
  20. #import "CCAlertShowView.h"
  21. #import "HSQUpdatePopView.h"
  22. #import "HSQGoodDetailViewController.h"
  23. #import "HSQGoodListViewController.h"
  24. #import "HSQAdWebViewController.h"
  25. //#import <UMSocialCore/UMSocialCore.h>
  26. #import "HYUMShareManager.h"
  27. #import "HSQFindSearchResultViewController.h"
  28. #import "GetScreenImage.h"
  29. #import "HSQScreenshotShareView.h"
  30. #import "NetworkTool.h"
  31. #import "PhoneLoginManager.h"
  32. #import "CreatSearchManager.h"
  33. #import "HSQMyFansViewController.h"
  34. #import "HSQAchievementViewController.h"
  35. #import "HSQChildAccountViewController.h"
  36. #import "HSQCollectionMainViewController.h"
  37. #import "HSQLoginViewController.h"
  38. #import "WWNetWorkingTool.h"
  39. #import "KXWKWebViewVC.h"
  40. #import "KXAdAlertModel.h"
  41. #import "XHLaunchAd.h"
  42. #import "HSQWebDetailController.h"
  43. #import "CALayer+Transition.h"
  44. @interface AppDelegate ()
  45. <
  46. MiPushSDKDelegate,
  47. UNUserNotificationCenterDelegate,
  48. UIApplicationDelegate,
  49. WXApiDelegate,
  50. XHLaunchAdDelegate
  51. >
  52. @property(nonatomic,strong)HSQScreenshotShareView *screenshotShareView;
  53. @property(nonatomic,strong)NSMutableArray *dataArray;;
  54. @end
  55. @implementation AppDelegate
  56. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  57. // Override point for customization after application launch.
  58. [self checkNetWorkState]; //监听网络并注册百川sdk
  59. [self setUpWeChat]; //微信sdk
  60. [self setDefauleSex]; //设置默认性别
  61. [self setUpSVProgressHUD]; //设置loading指示器
  62. [self setBugly]; //设置bugly
  63. [self setUMAnalisis]; //设置友盟统计
  64. [self setUMShareAndWeChartInfo]; //设置友盟分享和微信appkey和秘钥
  65. // [self addGuidepage]; //首次安装显示引导页
  66. [self setupKeyWindow];
  67. [self setupMiPush]; //小米推送
  68. [self cancelIconBadgeNumber]; //处理角标
  69. [self addRouteManager]; //初始化路由跳转
  70. [self getRemoteNotificationDictWithDict:launchOptions]; //设置点击推送跳转
  71. [self loadPhoneLogInButton];
  72. [self addXHAdvert];
  73. return YES;
  74. }
  75. - (void)checkNetWorkState {
  76. //创建网络监听管理者对象
  77. AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
  78. //设置监听
  79. __weak typeof(manager) weakManager = manager;
  80. [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
  81. BOOL isReachable = (status == AFNetworkReachabilityStatusReachableViaWiFi
  82. || status == AFNetworkReachabilityStatusReachableViaWWAN);
  83. if (isReachable) {
  84. NSLog(@"啊啊啊啊啊啊啊啊啊,有网络诶!!!!");
  85. [self setupAlibcSDK];
  86. [weakManager stopMonitoring];
  87. }
  88. }];
  89. //开始监听
  90. [manager startMonitoring];
  91. }
  92. -(void)test{
  93. // [[GetScreenImage shareInstance] startListening];
  94. }
  95. -(void)clickEnter
  96. {
  97. [self setupKeyWindow];
  98. }
  99. -(void)setUMWeChat{
  100. [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:WX_APPID appSecret:WX_APP_SECRET redirectURL:nil];
  101. }
  102. - (void)setUpWeChat {
  103. [WXApi registerApp:WX_APPID];
  104. }
  105. - (void)setupMiPush {
  106. [MiPushSDK registerMiPush:self];
  107. }
  108. - (void)setBugly {
  109. [Bugly startWithAppId:BUGLY_ID];
  110. }
  111. -(void)setUMAnalisis
  112. {
  113. UMConfigInstance.appKey = UMAPP_KEY;
  114. UMConfigInstance.channelId = @"App Store";
  115. NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
  116. NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
  117. [MobClick setAppVersion:app_Version];
  118. [MobClick startWithConfigure:UMConfigInstance];
  119. [MobClick setLogEnabled:YES];
  120. }
  121. -(void)setUMShareAndWeChartInfo{
  122. [[HYUMShareManager shareInstance] setUMShare];
  123. }
  124. - (void)cancelIconBadgeNumber {
  125. // 注册显示应用程序BadgeNumber的通知
  126. UIApplication *application = [UIApplication sharedApplication];
  127. UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil];
  128. [application registerUserNotificationSettings:settings];
  129. if (application.applicationIconBadgeNumber > 0) {
  130. application.applicationIconBadgeNumber = 0;
  131. }
  132. }
  133. /**
  134. 设置默认性别
  135. */
  136. - (void)setDefauleSex {
  137. NSString *sex = [[NSUserDefaults standardUserDefaults] objectForKey:UserSexKey];
  138. if (sex.length == 0 || [sex isEqualToString:@""]) {
  139. //默认性别为女
  140. [[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:UserSexKey];
  141. }
  142. }
  143. /**
  144. 首次安装性别引导
  145. */
  146. - (void)firstLaunchingGuide {
  147. NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
  148. NSString *launched = [userDefaults objectForKey:@"launched"];
  149. if (!launched)
  150. {
  151. [self creatGuideView];
  152. launched = @"YES";
  153. [userDefaults setObject:launched forKey:@"launched"];
  154. [userDefaults synchronize];
  155. }
  156. }
  157. - (void)creatGuideView {
  158. HSQGuideView *guideView = [[HSQGuideView alloc] initWithFrame:self.window.bounds];
  159. [self.window addSubview:guideView];
  160. }
  161. /**
  162. 加载是否显示手机登录
  163. */
  164. - (void)loadPhoneLogInButton {
  165. NSString *url = [NSString stringWithFormat:@"%@/api/v2/channel/getDevByChannelId",BaseURL];
  166. NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
  167. NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
  168. NSDictionary *para = @{@"channel_id":Channel_id,
  169. @"version":app_Version
  170. };
  171. [HSQHttp get:url params:para success:^(id json) {
  172. if ([json[@"ios"] boolValue]) {
  173. //显示
  174. [PhoneLoginManager shareManager].showPhoneBtn = @(YES);
  175. }else {
  176. //隐藏
  177. [PhoneLoginManager shareManager].showPhoneBtn = @(NO);
  178. }
  179. } failure:^(NSError *error) {
  180. }];
  181. }
  182. // 启动广告图
  183. - (void)addXHAdvert {
  184. [WWNetWorkingTool sharedNetWorkTool];
  185. //设置你工程的启动页使用的是:LaunchImage 还是 LaunchScreen.storyboard(不设置默认:LaunchImage)
  186. [XHLaunchAd setLaunchSourceType:SourceTypeLaunchImage];
  187. //1.因为数据请求是异步的,请在数据请求前,调用下面方法配置数据等待时间.
  188. //2.设为3即表示:启动页将停留3s等待服务器返回广告数据,3s内等到广告数据,将正常显示广告,否则将不显示
  189. //3.数据获取成功,配置广告数据后,自动结束等待,显示广告
  190. //注意:请求广告数据前,必须设置此属性,否则会先进入window的的根控制器
  191. [XHLaunchAd setWaitDataDuration:2];
  192. //广告数据请求
  193. [[WWNetWorkingTool sharedNetWorkTool] post:[NSString stringWithFormat:@"%@/Advert/V1/getAdvert",advURL] parameter:@{@"space_sign" : @"24"} success:^(id responseObject) {
  194. NSNumber *code = responseObject[@"code"];
  195. if ([code isEqual:0]) {
  196. //
  197. }
  198. //广告数据转模型
  199. self.dataArray = [KXAdAlertModel mj_objectArrayWithKeyValuesArray:responseObject[@"res"]];
  200. if (self.dataArray.count<1) {
  201. return;
  202. }
  203. KXAdAlertModel *model = self.dataArray.firstObject;
  204. //配置广告数据
  205. XHLaunchImageAdConfiguration *imageAdconfiguration = [XHLaunchImageAdConfiguration defaultConfiguration];
  206. imageAdconfiguration.duration = 3;
  207. imageAdconfiguration.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-Fitsize(115));
  208. if (iPhoneX) {
  209. imageAdconfiguration.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-162);
  210. }
  211. //广告图片URLString/或本地图片名(.jpg/.gif请带上后缀)
  212. imageAdconfiguration.imageNameOrURLString = model.img_url;
  213. //广告点击打开页面参数(openModel可为NSString,模型,字典等任意类型)
  214. imageAdconfiguration.openModel = model.advert_url;
  215. //后台返回时,是否显示广告
  216. imageAdconfiguration.showEnterForeground = NO;
  217. //添加子视图
  218. UIView *bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height-Fitsize(115), [UIScreen mainScreen].bounds.size.width, Fitsize(115))];
  219. bottomView.backgroundColor = [UIColor whiteColor];
  220. NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
  221. NSString *icon = [[infoDictionary valueForKeyPath:@"CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles"] lastObject];
  222. UIImageView *appIconImg = [[UIImageView alloc]initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/2 - 25, 15, 50, 50)];
  223. appIconImg.image = [UIImage imageNamed:icon];
  224. appIconImg.layer.masksToBounds = YES;
  225. appIconImg.layer.cornerRadius = 5;
  226. [bottomView addSubview:appIconImg];
  227. UILabel *appNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 80, [UIScreen mainScreen].bounds.size.width, 20)];
  228. appNameLabel.text = infoDictionary[@"CFBundleDisplayName"];
  229. appNameLabel.font = [UIFont systemFontOfSize:16];
  230. appNameLabel.textColor = [UIColor darkGrayColor];
  231. appNameLabel.textAlignment = NSTextAlignmentCenter;
  232. [bottomView addSubview:appNameLabel];
  233. // imageAdconfiguration.subViews = @[bottomView];
  234. //显示开屏广告
  235. [XHLaunchAd imageAdWithImageAdConfiguration:imageAdconfiguration delegate:self];
  236. } faliure:^(id error) {
  237. //
  238. }];
  239. }
  240. /**
  241. 广告点击事件代理方法
  242. */
  243. -(void)xhLaunchAd:(XHLaunchAd *)launchAd clickAndOpenModel:(id)openModel clickPoint:(CGPoint)clickPoint{
  244. NSLog(@"广告点击事件");
  245. /** openModel即配置广告数据设置的点击广告时打开页面参数(configuration.openModel) */
  246. if (openModel == nil) {
  247. return;
  248. }
  249. //异步发送广告记录
  250. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  251. KXAdAlertModel *model = self.dataArray.firstObject;
  252. [[WWNetWorkingTool sharedNetWorkTool] post:[NSString stringWithFormat:@"%@/api/Advert/V1/advertRecord",advURL] parameter:@{@"space_sign" : @"24", @"advert_id" : model.ID} success:^(id responseObject) {
  253. //
  254. NSLog(@"%@", responseObject);
  255. } faliure:^(id error) {
  256. //
  257. }];
  258. });
  259. NSString *urlString = (NSString *)openModel;
  260. UIViewController *rootViewController = self.window.rootViewController;
  261. HSQWebDetailController *webVC = [[HSQWebDetailController alloc]init];
  262. webVC.url = urlString;
  263. NSArray *childsVC = [rootViewController childViewControllers];
  264. UINavigationController *navVC = childsVC.firstObject;
  265. [navVC pushViewController:webVC animated:YES];
  266. }
  267. /**
  268. 配置阿里百川SDK
  269. */
  270. - (void)setupAlibcSDK {
  271. // 百川平台基础SDK初始化,加载并初始化各个业务能力插件
  272. [[AlibcTradeSDK sharedInstance] asyncInitWithSuccess:^{
  273. } failure:^(NSError *error) {
  274. NSLog(@"Init failed: %@", error.description);
  275. }];
  276. // 开发阶段打开日志开关,方便排查错误信息
  277. //默认调试模式打开日志,release关闭,可以不调用下面的函数
  278. // [[AlibcTradeSDK sharedInstance] setDebugLogOpen:YES];
  279. // 配置全局的淘客参数
  280. //如果没有阿里妈妈的淘客账号,setTaokeParams函数需要调用
  281. AlibcTradeTaokeParams *taokeParams = [[AlibcTradeTaokeParams alloc] init];
  282. taokeParams.pid = ALTK_PID; //mm_XXXXX为你自己申请的阿里妈妈淘客pid
  283. [[AlibcTradeSDK sharedInstance] setTaokeParams:taokeParams];
  284. //设置全局的app标识,在电商模块里等同于isv_code
  285. //没有申请过isv_code的接入方,默认不需要调用该函数
  286. [[AlibcTradeSDK sharedInstance] setISVCode:@"your_isv_code"];
  287. // 设置全局配置,是否强制使用h5
  288. [[AlibcTradeSDK sharedInstance] setIsForceH5:NO];
  289. }
  290. - (void)setupKeyWindow {
  291. self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  292. HSQTabbarController *tab = [[HSQTabbarController alloc] init];
  293. self.window.rootViewController = tab;
  294. self.window.backgroundColor = [UIColor whiteColor];
  295. [self.window makeKeyAndVisible];
  296. }
  297. - (void)setUpSVProgressHUD {
  298. [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
  299. [SVProgressHUD setForegroundColor:[UIColor YHColorWithHex:0xff2420]];
  300. [SVProgressHUD setBackgroundColor:[UIColor YHColorWithHex:0xf5f4f4]];
  301. [SVProgressHUD setMinimumDismissTimeInterval:2];
  302. }
  303. - (void)addRouteManager {
  304. // [RouteManager registerRouteWithScheme:SchemeKey];
  305. }
  306. /**
  307. 点击通知跳转到指定页面
  308. */
  309. - (void)getRemoteNotificationDictWithDict:(NSDictionary *)tfdic {
  310. NSDictionary *remoteNotification = [tfdic objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
  311. if(remoteNotification){
  312. NSString *messageId;
  313. if ([remoteNotification containsObjectForKey:@"_id_"]) {
  314. messageId = [remoteNotification objectForKey:@"_id_"];
  315. }
  316. if (messageId!=nil) {
  317. [MiPushSDK openAppNotify:messageId];
  318. }
  319. }
  320. [self jumpViewController:remoteNotification];
  321. }
  322. - (void)jumpViewController:(NSDictionary *)remoteNotification {
  323. NSInteger pushType = [remoteNotification[@"pushType"] integerValue];
  324. switch (pushType) {
  325. case 1000:
  326. {
  327. HSQEventModel *evevtModel = [[HSQEventModel alloc] initWithOrigin:@"0" category_id:@"0" source:pushAction];
  328. HSQGoodDetailViewController *detail = [[HSQGoodDetailViewController alloc] init];
  329. if ([remoteNotification.allKeys containsObject:@"goods_id"]) {
  330. DetailRequestModel *requestModel = [DetailRequestModel yy_modelWithJSON:remoteNotification];
  331. detail.requestModel = requestModel;
  332. }
  333. detail.eventModel = evevtModel;
  334. [[self currentViewController].navigationController pushViewController:detail animated:YES];
  335. }
  336. break;
  337. case 1001:
  338. {
  339. //列表
  340. HSQGoodListViewController *list = [[HSQGoodListViewController alloc] init];
  341. if ([remoteNotification.allKeys containsObject:@"gid"]) {
  342. list.cate_id = remoteNotification[@"gid"];
  343. }else {
  344. list.cate_id = @"";
  345. }
  346. if ([remoteNotification.allKeys containsObject:@"name"]) {
  347. list.name = remoteNotification[@"name"];
  348. }else {
  349. list.name = @"";
  350. }
  351. list.topRequest = 2;
  352. [[self currentViewController].navigationController pushViewController:list animated:YES];
  353. }
  354. break;
  355. case 1002:
  356. {
  357. HSQAdWebViewController *web = [[HSQAdWebViewController alloc] init];
  358. if ([remoteNotification.allKeys containsObject:@"url"]) {
  359. web.url = remoteNotification[@"url"];
  360. }else {
  361. web.url = @"";
  362. }
  363. //h5
  364. [[self currentViewController].navigationController pushViewController:web animated:YES];
  365. }
  366. break;
  367. case 1003:
  368. {
  369. //我的好友
  370. if (![AccountTool isLogin]) {
  371. [self goToLoginPage];
  372. return;
  373. }
  374. HSQMyFansViewController *collection = [[HSQMyFansViewController alloc] init];
  375. [[self currentViewController].navigationController pushViewController:collection animated:YES];
  376. }
  377. break;
  378. case 1004:
  379. {
  380. //我的收益
  381. if (![AccountTool isLogin]) {
  382. [self goToLoginPage];
  383. return;
  384. }
  385. HSQAchievementViewController *collection = [[HSQAchievementViewController alloc] init];
  386. [[self currentViewController].navigationController pushViewController:collection animated:YES];
  387. }
  388. break;
  389. case 1005:
  390. {
  391. //我的账户
  392. if (![AccountTool isLogin]) {
  393. [self goToLoginPage];
  394. return;
  395. }
  396. HSQChildAccountViewController *collection = [[HSQChildAccountViewController alloc] init];
  397. [[self currentViewController].navigationController pushViewController:collection animated:YES];
  398. }
  399. break;
  400. case 1006:
  401. {
  402. //收藏
  403. if (![AccountTool isLogin]) {
  404. [self goToLoginPage];
  405. return;
  406. }
  407. HSQCollectionMainViewController *collection = [[HSQCollectionMainViewController alloc] init];
  408. [[self currentViewController].navigationController pushViewController:collection animated:YES];
  409. }
  410. break;
  411. default:
  412. break;
  413. }
  414. }
  415. - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
  416. [[UMSocialManager defaultManager] handleOpenURL:url sourceApplication:sourceApplication annotation:annotation];
  417. NSString *urlStr = url.absoluteString;
  418. if ([urlStr hasPrefix:SchemeKey]) {
  419. return [[JLRoutes routesForScheme:SchemeKey] routeURL:url];
  420. }
  421. // if ([urlStr hasPrefix:WX_APPID]) {
  422. // return [WXApi handleOpenURL:url delegate:[WXApiManager sharedManager]];
  423. // }
  424. // 新接口写法
  425. if (![[AlibcTradeSDK sharedInstance] application:application
  426. openURL:url
  427. sourceApplication:sourceApplication
  428. annotation:annotation]) {
  429. // 处理其他app跳转到自己的app
  430. }
  431. return YES;
  432. }
  433. // ios9 新api
  434. - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {
  435. //微信分享
  436. [[UMSocialManager defaultManager] handleOpenURL:url options:options];
  437. NSString *urlStr = url.absoluteString;
  438. if ([urlStr hasPrefix:SchemeKey]) {
  439. return [[JLRoutes routesForScheme:SchemeKey] routeURL:url];
  440. }
  441. // if ([urlStr hasPrefix:WX_APPID]) {
  442. // return [WXApi handleOpenURL:url delegate:[WXApiManager sharedManager]];
  443. // }
  444. // 新接口写法
  445. if (@available(iOS 9.0, *)) {
  446. if (![[AlibcTradeSDK sharedInstance] application:application
  447. openURL:url
  448. options:options]) {
  449. //处理其他app跳转到自己的app,如果百川处理过会返回YES
  450. }
  451. } else {
  452. // Fallback on earlier versions
  453. }
  454. return YES;
  455. }
  456. #pragma mark 注册push服务.
  457. - (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
  458. {
  459. NSLog(@"APNS token: %@", [deviceToken description]);
  460. // 注册APNS成功, 注册deviceToken
  461. [MiPushSDK bindDeviceToken:deviceToken];
  462. }
  463. - (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err
  464. {
  465. NSLog(@"APNS error: %@", err);
  466. // 注册APNS失败.
  467. // 自行处理.
  468. }
  469. #pragma mark MiPushSDKDelegate
  470. - (void)miPushRequestSuccWithSelector:(NSString *)selector data:(NSDictionary *)data
  471. {
  472. // 请求成功
  473. // 可在此获取regId
  474. if ([selector isEqualToString:@"bindDeviceToken:"]) {
  475. NSLog(@"regid = %@", data[@"regid"]);
  476. }
  477. }
  478. - (void)miPushRequestErrWithSelector:(NSString *)selector error:(int)error data:(NSDictionary *)data
  479. {
  480. // 请求失败
  481. }
  482. #pragma mark Local And Push Notification
  483. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
  484. {
  485. NSLog(@"APNS notify: %@", userInfo);
  486. // 当同时启动APNs与内部长连接时, 把两处收到的消息合并. 通过miPushReceiveNotification返回
  487. [MiPushSDK handleReceiveRemoteNotification:userInfo];
  488. }
  489. // iOS10新加入的回调方法
  490. // 应用在前台收到通知
  491. - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler __IOS_AVAILABLE(10.0) {
  492. NSDictionary * userInfo = notification.request.content.userInfo;
  493. if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
  494. NSLog(@"APNS notify: %@", userInfo);;
  495. [MiPushSDK handleReceiveRemoteNotification:userInfo];
  496. NSString *messageId = [userInfo objectForKey:@"_id_"];
  497. [MiPushSDK openAppNotify:messageId];
  498. }
  499. [self cancelIconBadgeNumber];
  500. }
  501. // 点击通知进入应用
  502. - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler __IOS_AVAILABLE(10.0) {
  503. NSDictionary * userInfo = response.notification.request.content.userInfo;
  504. if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
  505. NSLog(@"APNS notify: %@", userInfo);
  506. [MiPushSDK handleReceiveRemoteNotification:userInfo];
  507. NSString *messageId = [userInfo objectForKey:@"_id_"];
  508. [MiPushSDK openAppNotify:messageId];
  509. }
  510. [self jumpViewController:userInfo];
  511. completionHandler();
  512. }
  513. #pragma mark MiPushSDKDelegate
  514. - (void)applicationWillResignActive:(UIApplication *)application {
  515. // 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.
  516. // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
  517. }
  518. - (void)applicationDidEnterBackground:(UIApplication *)application {
  519. // 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.
  520. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
  521. [SVProgressHUD dismiss];
  522. [self cancelIconBadgeNumber];
  523. }
  524. - (void)applicationWillEnterForeground:(UIApplication *)application {
  525. // 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.
  526. }
  527. - (void)applicationDidBecomeActive:(UIApplication *)application {
  528. [self checkPasteboardText]; //识别剪贴板
  529. //判断是否开启通知
  530. [[NSNotificationCenter defaultCenter] postNotificationName:@"setMessage" object:nil];
  531. }
  532. - (void)applicationWillTerminate:(UIApplication *)application {
  533. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
  534. }
  535. #pragma mark ----
  536. - (void)checkPasteboardText {
  537. UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
  538. NSString *pasteText = pasteBoard.string;
  539. if (pasteText.length > 0 && [self isNum:pasteText]) {
  540. return;
  541. }
  542. if (pasteText.length > 10) {
  543. HSQSearchPopView *popView = [[HSQSearchPopView alloc] initWithFrame:CGRectMake(0, 0, Fitsize(310), Fitsize(246)) searchText:pasteText];
  544. CCAlertShowView *showView = [CCAlertShowView showAlertViewWithView:popView backgroundDismissEnable:YES];
  545. popView.cancelClick = ^{
  546. [showView dismiss];
  547. };
  548. popView.searchlClick = ^{
  549. // HSQFindSearchResultViewController *result = [[HSQFindSearchResultViewController alloc] init];
  550. // result.searchName = pasteText;
  551. // result.hiddenNavigationWhenPop = YES;
  552. // [[self currentViewController].navigationController pushViewController:result animated:YES];
  553. CreatSearchManager *manager = [[CreatSearchManager alloc] init];
  554. [manager createSearchViewControllerWith:pasteText viewController:[self currentViewController]];
  555. [showView dismiss];
  556. [MobClick event:popCopySearch];
  557. };
  558. pasteBoard.string = @"";
  559. }
  560. }
  561. - (UIViewController *)currentViewController{
  562. UIViewController * currVC = nil;
  563. UIWindow *window = [UIApplication sharedApplication].delegate.window;
  564. UIViewController * Rootvc = window.rootViewController;
  565. do {
  566. if ([Rootvc isKindOfClass:[UINavigationController class]]) {
  567. UINavigationController * nav = (UINavigationController *)Rootvc;
  568. UIViewController * v = [nav.viewControllers lastObject];
  569. currVC = v;
  570. Rootvc = v.presentedViewController;
  571. continue;
  572. }else if([Rootvc isKindOfClass:[UITabBarController class]]){
  573. UITabBarController * tabVC = (UITabBarController *)Rootvc;
  574. currVC = tabVC;
  575. Rootvc = [tabVC.viewControllers objectAtIndex:tabVC.selectedIndex];
  576. continue;
  577. }
  578. } while (Rootvc!=nil);
  579. return currVC;
  580. }
  581. - (void)goToLoginPage {
  582. HSQLoginViewController *login = [[HSQLoginViewController alloc] init];
  583. [[self currentViewController] presentViewController:login animated:YES completion:nil];
  584. }
  585. - (NSMutableArray *)dataArray {
  586. if (!_dataArray) {
  587. _dataArray = [NSMutableArray array];
  588. }
  589. return _dataArray;
  590. }
  591. /**
  592. 识别是否为纯数字
  593. */
  594. - (BOOL)isNum:(NSString *)checkedNumString {
  595. checkedNumString = [checkedNumString stringByTrimmingCharactersInSet:[NSCharacterSet decimalDigitCharacterSet]];
  596. if(checkedNumString.length > 0) {
  597. return NO;
  598. }
  599. return YES;
  600. }
  601. @end