重庆迈尖科技有限公司
2018-08-20 b8c74010cb15ca3145f06dba2d9ed4fcb1d0a8bc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
//
//  AppDelegate.m
//  MIduo
//
//  Created by apple on 17/2/20.
//  Copyright © 2017年 yeshi. All rights reserved.
//
 
#import "AppDelegate.h"
 
//#import "XGPush.h"                         //信鸽
//#import "XGSetting.h"
#import <UserNotifications/UserNotifications.h>
 
#import "BaseNavigationController.h"
#import "NEWHomeViewController.h"
#import "classificationViewController.h"
#import "shoppingCartViewController.h"
#import "DynamicViewController.h"
#import "MineViewController.h"
#import "MainInviteViewController.h"
 
#import <ShareSDK/ShareSDK.h>
#import <ShareSDKConnector/ShareSDKConnector.h>
 
//腾讯开放平台(对应QQ和QQ空间)SDK头文件
#import <TencentOpenAPI/TencentOAuth.h>
#import <TencentOpenAPI/QQApiInterface.h>
 
//微信SDK头文件
#import "WXApi.h"
 
//新浪微博SDK头文件
#import "WeiboSDK.h"
 
//#import "MiPushSDK.h"
#import  <UserNotifications/UserNotifications.h>
 
#import <WeexSDK/WXSDKInstance.h>
#import <WeexSDK/WeexSDK.h>
 
#import "WXAppConfiguration.h"
#import "WXSDKEngine.h"
#import "WXLog.h"
#import "SJModule.h"
#import "SJNComponet.h"
#import "WXImgLoaderDefaultImpl.h"
//#import "WXNavigationDefaultImpl.h"
 
/****** Weex ******/
// SDK
#import <WeexSDK/WeexSDK.h>
// Module
#import "WXUserModule.h"
#import "WXUtilModule.h"
// Component
#import "WXCutomNewStrategyComponent.h"
 
@interface AppDelegate ()<UNUserNotificationCenterDelegate,UITabBarControllerDelegate,WXApiDelegate>
 
@end
 
@implementation AppDelegate
 
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    //阿里百川
    [self setAliTrade];
    
    //清空角标
    [UIApplication sharedApplication].applicationIconBadgeNumber=0;
    
    //设置tabBar的字体颜色
    [self setTabBarItemFontColor];
    
    //配置
    [self Configuration];
    
    //监听网络
    [self netWorkChangeEvent];
    
    //weex
    [self WeexInit];
    
    //友盟
    [self setUmeng];
    [UMConfigure setLogEnabled:YES];
    
    //配置客户端信息
    [self getInfoFromCompany];
    
    //微信登录
    [self WeiXinChatLogin];
    [self loadViews];
    
 
    NSDictionary * userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
    if(userInfo){
        _isLaunch=YES;
        //        [self loginDeviceToken];
        if(iOS10){
            [NSTimer scheduledTimerWithTimeInterval:1.0 repeats:NO block:^(NSTimer * _Nonnull timer) {
                
            }];
        }
    }
    
    [SVProgressHUD setMinimumDismissTimeInterval:2.0];
    
    
    [ShareSDK registerActivePlatforms:@[@(SSDKPlatformTypeSinaWeibo),
                                        @(SSDKPlatformTypeMail),
                                        @(SSDKPlatformTypeSMS),
                                        @(SSDKPlatformTypeCopy),
                                        @(SSDKPlatformTypeWechat),
                                        @(SSDKPlatformTypeQQ),
                                        @(SSDKPlatformTypeRenren),
                                        @(SSDKPlatformTypeFacebook),
                                        @(SSDKPlatformTypeTwitter),
                                        @(SSDKPlatformTypeGooglePlus)
                                        ]
                             onImport:^(SSDKPlatformType platformType)
     {
         switch (platformType)
         {
             case SSDKPlatformTypeWechat:
                 [ShareSDKConnector connectWeChat:[WXApi class]];
                 break;
             case SSDKPlatformTypeQQ:
                 [ShareSDKConnector connectQQ:[QQApiInterface class] tencentOAuthClass:[TencentOAuth class]];
                 break;
             case SSDKPlatformTypeSinaWeibo:
                 [ShareSDKConnector connectWeibo:[WeiboSDK class]];
                 
                 break;
             default:
                 break;
         }
     }
                      onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo)
     {
         /*  //友盟分享
          [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:@"wx5c0d167c6e3ad726" appSecret:@"0c79d5869bb0f2d7c13e43f9a18f440d" redirectURL:nil];//微信
          
          [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_QQ appKey:@"1106259063" appSecret:nil redirectURL:@"http://mobile.umeng.com/social"];//QQ
          
          [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Sina appKey:@"3403499693"  appSecret:@"aa1c7b53c4d34b634dcc6c1ed36f48ce" redirectURL:@"https://sns.whalecloud.com/sina2/callback"];//新浪*/
         switch (platformType)
         {
             case SSDKPlatformTypeSinaWeibo:
                 //设置新浪微博应用信息,其中authType设置为使用SSO+Web形式授权
                 [appInfo SSDKSetupSinaWeiboByAppKey:@"3403499693"
                                           appSecret:@"aa1c7b53c4d34b634dcc6c1ed36f48ce"
                                         redirectUri:@"https://sns.whalecloud.com/sina2/callback"
                                            authType:SSDKAuthTypeBoth];
                 break;
             case SSDKPlatformTypeWechat:
                 [appInfo SSDKSetupWeChatByAppId:@"wx5c0d167c6e3ad726"
                                       appSecret:@"0c79d5869bb0f2d7c13e43f9a18f440d"];
                 break;
             case SSDKPlatformTypeQQ:
                 [appInfo SSDKSetupQQByAppId:@"1106259063"
                                      appKey:@"aed9b0303e3ed1e27bae87c33761161d"
                                    authType:SSDKAuthTypeBoth];
                 break;
             default:
                 break;
         }
     }];
    
    //点击首页的tabbarItem,回到顶部
    UITabBarController *baseTabBar = (UITabBarController *)self.window.rootViewController;
    
    baseTabBar.delegate=self;
    
    if (IOS_VERSION >= 10.0) {
        
        UNUserNotificationCenter * center = [UNUserNotificationCenter currentNotificationCenter];
        
        [center setDelegate:self];
        
        UNAuthorizationOptions type = UNAuthorizationOptionBadge|UNAuthorizationOptionSound|UNAuthorizationOptionAlert;
        
        [center requestAuthorizationWithOptions:type completionHandler:^(BOOL granted, NSError * _Nullable error) {
            
            if (granted) {
                
                ALLog(@"注册成功");
                
            }else{
                
                ALLog(@"注册失败");
            }
        }];
        
    } else if (IOS_VERSION >= 8.0) {
        
        UIUserNotificationType notificationTypes = UIUserNotificationTypeBadge |
        
        UIUserNotificationTypeSound |
        
        UIUserNotificationTypeAlert;
        
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:notificationTypes categories:nil];
        
        [application registerUserNotificationSettings:settings];
        
    } else {// ios8以下
        
        UIRemoteNotificationType notificationTypes = UIRemoteNotificationTypeBadge |
        
        UIRemoteNotificationTypeSound |
        
        UIRemoteNotificationTypeAlert;
        
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:notificationTypes];
    }
    //
    // if (launchOptions) {
    // 获取推送通知定义的userinfo
    // UILocalNotification *notification = launchOptions[UIApplicationLaunchOptionsLocalNotificationKey];
    // NSString *controller = notification.userInfo[@"controller"];
    // 这里就是告诉程序我要跳转到哪里
    // [YTHsharedManger startManger].infomation = userInfo;
    // [[NSNotificationCenter defaultCenter] postNotification:notification];
    // [[NSNotificationCenter defaultCenter] postNotificationName:@"pushInfomation" object:userInfo];
    // }
    
    // 注册获得device Token
    [application registerForRemoteNotifications];
    
    return YES;
}
 
#pragma mark --- Weex初始化配置 ---
- (void)WeexInit {
    
    // business configuration
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
 
    [WXAppConfiguration setAppGroup:@"AliApp"];
    [WXAppConfiguration setAppName:app_Name];
    [WXAppConfiguration setAppVersion:app_Version];
    
    // init sdk environment
    [WXSDKEngine initSDKEnvironment];
    
    // register custom module and component,optional
    [WXSDKEngine registerComponent:@"navgation" withClass:[SJNComponet class]];
    [WXSDKEngine registerComponent:@"topMenu" withClass:[WXCutomNewStrategyComponent class]];
    
    // [WXSDKEngine registerModule:@"event" withClass:[SJModule class]];
    [WXSDKEngine registerModule:@"userModule" withClass:[WXUserModule class]];
    [WXSDKEngine registerModule:@"utilModule" withClass:[WXUtilModule class]];
    
    // register the implementation of protocol, optional
    [WXSDKEngine registerHandler:[WXImgLoaderDefaultImpl new] withProtocol:@protocol(WXImgLoaderProtocol)];
    
    // 设置日志级别
    [WXLog setLogLevel:WXLogLevelError];
}
 
- (void)loginDeviceToken {
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[YTHsharedManger startManger].deviceToken forKey:@"deviceToken"];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"] forKey:@"uid"];
    
    [JYNetWorking Post:[NSString stringWithFormat:@"%@/%@",domainHTTP,@"push/uidBindDeviceToken"] param:dic success:^(NSDictionary *object) {
        NSLog(@"%@",object);
    } fail:^(id object) {
        NSLog(@"%@",object);
    }];
}
- (void)loadViews {
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor=[UIColor whiteColor];
    [self.window makeKeyAndVisible];
    NEWHomeViewController *recommendVC = [[NEWHomeViewController alloc]init];
    recommendVC.tabBarItem.title = @"精选";
    recommendVC.tabBarItem.selectedImage = [UIImage imageNamed:@"Home点击"];
    recommendVC.tabBarItem.image = [UIImage imageNamed:@"Home"];
    BaseNavigationController *nrecommendVC = [[BaseNavigationController alloc]initWithRootViewController:recommendVC];
    
    classificationViewController *subVC = [[classificationViewController alloc]init];
    subVC.tabBarItem.title = @"优惠券";
    subVC.tabBarItem.selectedImage = [UIImage imageNamed:@"优惠券点击"];
    subVC.tabBarItem.image = [UIImage imageNamed:@"优惠券"];
    BaseNavigationController *nsubVC = [[BaseNavigationController alloc]initWithRootViewController:subVC];
    
    MainInviteViewController *invateVC = [[MainInviteViewController alloc]init];
    //    invateVC..image = [[UIImage imageNamed:@"邀请有奖"] ];
    invateVC.tabBarItem.image = [[UIImage imageNamed:@"邀请有奖"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];;
    invateVC.tabBarItem.imageInsets = UIEdgeInsetsMake(3, 0, -3, 0);
    BaseNavigationController *ninvateVC = [[BaseNavigationController alloc]initWithRootViewController:invateVC];
    
    //    shoppingCartViewController *disVC = [[shoppingCartViewController alloc]init];
    //    disVC.tabBarItem.title = @"购物车";
    //    disVC.tabBarItem.selectedImage = [UIImage imageNamed:@"Cart点击"];
    //    disVC.tabBarItem.image = [UIImage imageNamed:@"Cart"];
    //    BaseNavigationController *ndisVC = [[BaseNavigationController alloc]initWithRootViewController:disVC];
    //    DynamicViewController
    DynamicViewController *disVC = [[DynamicViewController alloc]init];
    disVC.tabBarItem.title = @"动态";
    disVC.tabBarItem.selectedImage = [UIImage imageNamed:@"动态2"];
    disVC.tabBarItem.image = [UIImage imageNamed:@"动态"];
    BaseNavigationController *ndisVC = [[BaseNavigationController alloc]initWithRootViewController:disVC];
    
    MineViewController *mineVC = [[MineViewController alloc]init];
    mineVC.tabBarItem.title = @"我的";
    mineVC.tabBarItem.selectedImage = [UIImage imageNamed:@"Profile点击"];
    mineVC.tabBarItem.image = [UIImage imageNamed:@"Profile"];
    BaseNavigationController *nmineVC = [[BaseNavigationController alloc]initWithRootViewController:mineVC];
    
    UITabBarController *tabBarController = [[UITabBarController alloc]init];
    //    SJTabbar *tabbar = [[SJTabbar alloc]init];
    //    tabBarController.tabBar = tabbar;
    [[UITabBar appearance] setBackgroundColor:XYRBackgroundColor];
    tabBarController.viewControllers = @[nrecommendVC,nsubVC,ninvateVC,ndisVC,nmineVC];
    tabBarController.tabBar.tintColor = YTHColor(229, 0, 92);
    
    NSMutableDictionary *attr3=[NSMutableDictionary dictionary];
    attr3[NSFontAttributeName]=[UIFont systemFontOfSize:10];
    [[UITabBarItem appearance]setTitleTextAttributes:attr3 forState:UIControlStateNormal];
    
    self.window.rootViewController = tabBarController;
    
    if([[NSUserDefaults standardUserDefaults] objectForKey:@"userId"]!=nil){
        [self getMessage];
    }
}
- (void)getMessage{
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    
    [dic setObject:@"1" forKey:@"page"];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"] forKey:@"uid"];
    
    [JYNetWorking Post:[NSString stringWithFormat:@"%@/%@",domainHTTP,@"customer/findAccountMessageList"]
                 param:dic
               success:^(NSDictionary *object) {
                   
        ALLog(@"%@",object);
        // NSInteger code = [object[@"code"]integerValue];
        NSDictionary *dic = object[@"data"];
        NSArray *array = dic[@"list"];
        BOOL bor = NO;
        for (NSInteger index = 0; index < array.count; index ++) {
            NSDictionary *dic = array[index];
            if (![dic[@"isOpen"]boolValue]) {
                bor = YES;
                break;
            }
        }
        if (bor) {
            UITabBarController *baseTabBar = (UITabBarController *)self.window.rootViewController;
            [baseTabBar.tabBar showBadgeOnItemIndex:3];
        }else{
            UITabBarController *baseTabBar = (UITabBarController *)self.window.rootViewController;
            [baseTabBar.tabBar hideBadgeOnItemIndex:3];
        }
        
    } fail:^(id object) {
        NSLog(@"%@",object);
    }];
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {
    
    // 新接口写法
    if (![[AlibcTradeSDK sharedInstance] application:application
                                             openURL:url
                                             options:options]) {
        //处理其他app跳转到自己的app,如果百川处理过会返回YES
        return [WXApi handleOpenURL:url delegate:self];
    }
    
    
    return YES;
}
 
 
- (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.
    
    
}
 
 
- (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.
   
    [self boardCheck];
    
    if ([YTHsharedManger startManger].isEnterForeground) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"isEnterForeground" object:nil];
    }
}
 
#pragma mark --- 查看粘贴板 ---
- (void)boardCheck {
 
    UIPasteboard *board = [UIPasteboard generalPasteboard];
    
    if (board.string != nil) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"GUESSYOULIKE" object:board.string];
        UIPasteboard*pasteboard = [UIPasteboard generalPasteboard];
        pasteboard.string=@"";
    }
}
 
- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
 
//获取当前屏幕显示的viewcontroller
- (UIViewController *)getCurrentVC{
    UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
    UIViewController *currentVC = [self getCurrentVCFrom:rootViewController];
    return currentVC;
}
 
- (UIViewController *)getCurrentVCFrom:(UIViewController *)rootVC{
    UIViewController *currentVC;
    
    if ([rootVC presentedViewController]) {
        // 视图是被presented出来的
        rootVC = [rootVC presentedViewController];
    }
    if ([rootVC isKindOfClass:[UITabBarController class]]) {
        // 根视图为UITabBarController
        currentVC = [self getCurrentVCFrom:[(UITabBarController *)rootVC selectedViewController]];
    } else if ([rootVC isKindOfClass:[UINavigationController class]]){
        // 根视图为UINavigationController
        currentVC = [self getCurrentVCFrom:[(UINavigationController *)rootVC visibleViewController]];
    } else {
        // 根视图为非导航类
        currentVC = rootVC;
    }
    
    return currentVC;
}
 
//原生
-(void)WeiXinChatLogin{
    [WXApi registerApp:@"wx5c0d167c6e3ad726"];
}
 
- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
 
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    
    if (![[AlibcTradeSDK sharedInstance] application:application
                                             openURL:url
                                   sourceApplication:sourceApplication
                                          annotation:annotation]) {
        // 处理其他app跳转到自己的app
    }
    
    //该URL是否已经被SDK处理过
    if ([[ALBBSDK sharedInstance] isTBBackUrl:url.absoluteString]) {
        [[ALBBSDK sharedInstance] loginByURL:url];
        
        //开发者继续自己处理
        [[ALBBSDK sharedInstance] setLoginResultHandler:^(ALBBSession *session) {
            if(session.isLogin){
                [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"TaoBaoLogin"];
            }else{
                [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"TaoBaoLogin"];
            }
        }];
    }
    
    //友盟分享
    BOOL result = [[UMSocialManager defaultManager] handleOpenURL:url sourceApplication:sourceApplication annotation:annotation];
    if (result) {
        return result;
    }
    
    return [WXApi handleOpenURL:url delegate:self];
}
 
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
    return [WXApi handleOpenURL:url delegate:self];
}
 
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    
    //NSString *accountStr=[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"];
    
    NSString *deviceTokenStr = [[[[deviceToken description]
                                  
                                  stringByReplacingOccurrencesOfString:@"<" withString:@""]
                                 
                                 stringByReplacingOccurrencesOfString:@">" withString:@""]
                                
                                stringByReplacingOccurrencesOfString:@" " withString:@""];
    
    NSLog(@"deviceTokenStr:\n%@",deviceTokenStr);
    [YTHsharedManger startManger].deviceToken = deviceTokenStr;
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    
    [dic setObject:deviceTokenStr forKey:@"deviceToken"];
    
    NSLog(@"%@",[NSString stringWithFormat:@"%@/%@",domainHTTP,@"push/insertDeviceToken"]);
    [JYNetWorking Post:[NSString stringWithFormat:@"%@/%@",domainHTTP,@"push/insertDeviceToken"] param:dic success:^(NSDictionary *object) {
        NSLog(@"%@",object);
        //        NSInteger code = [object[@"code"]integerValue];
        //        [self.datasource removeAllObjects];
        
    } fail:^(id object) {
        NSLog(@"%@",object);
    }];
    if([[NSUserDefaults standardUserDefaults] objectForKey:@"userId"]!=nil){
        [self loginDeviceToken];
        
    }
}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err
{
    // 注册APNS失败
    // 自行处理
    NSLog(@"%@",err);
}
 
/**
 收到通知的回调
 
 @param application  UIApplication 实例
 @param userInfo 推送时指定的参数
 */
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    //    UIApplicationStateActive 应用程序处于前台
    NSLog(@"%@",userInfo);
    if(application.applicationState == UIApplicationStateActive){
        
        //程序当前正处于前台
        //发送本地通知
        NSTimeInterval nowtime = [[NSDate date] timeIntervalSince1970];
        NSInteger theTime = [[NSNumber numberWithDouble:nowtime] unsignedIntegerValue];
        [self registerLocalNotification:(int)theTime alertBody:[[userInfo objectForKey:@"aps"] objectForKey:@"alert"] userDict:userInfo];
    }
    //    UIApplicationStateBackground 应用程序在后台,用户从通知中心点击消息将程序从后台调至前台
    if(application.applicationState == UIApplicationStateBackground){
        
    }
}
 
/**
 收到本地通知的回调
 
 @param application UIApplication 实例
 */
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notifications{
    if(application.applicationState == UIApplicationStateActive){
        //程序当前正处于前台
        
    }else{
        
    }
}
 
/**
 收到静默推送的回调
 
 @param application  UIApplication 实例
 @param userInfo 推送时指定的参数
 @param completionHandler 完成回调
 */
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    NSLog(@"[XGDemo] userinfo %@", userInfo);
    if(application.applicationState == UIApplicationStateActive){
        //程序当前正处于前台
        //发送本地通知
        NSTimeInterval nowtime = [[NSDate date] timeIntervalSince1970];
        NSInteger theTime = [[NSNumber numberWithDouble:nowtime] unsignedIntegerValue];
        [self registerLocalNotification:theTime alertBody:[[userInfo objectForKey:@"aps"] objectForKey:@"alert"] userDict:userInfo];
    }
    if(application.applicationState == UIApplicationStateBackground){
        //程序当前正处于后台
    }
    completionHandler(UIBackgroundFetchResultNewData);
}
 
// iOS 10 新增 API
// iOS 10 会走新 API, iOS 10 以前会走到老 API
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
// App 用户点击通知的回调
// 无论本地推送还是远程推送都会走这个回调
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler {
    NSLog(@"[XGDemo] click notification");
    NSDictionary * userInfo = response.notification.request.content.userInfo;
    [YTHsharedManger startManger].infomation = userInfo;
    //    [[NSNotificationCenter defaultCenter] postNotification:notification];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"pushInfomation" object:userInfo];
    
    completionHandler();
}
 
// App 在前台弹通知需要调用这个接口
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
    
    //NSDictionary * userInfo = notification.request.content.userInfo;
    
    if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
        // [MiPushSDK handleReceiveRemoteNotification:userInfo];
    }
    // completionHandler(UNNotificationPresentationOptionAlert);
    
    completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert);
}
#endif
 
- (void)registerLocalNotification:(NSInteger)alertTime alertBody:(NSString *)alertBody userDict:(NSDictionary *)userDict
{
    UILocalNotification *notification = [[UILocalNotification alloc] init];
    // 设置触发通知的时间
    NSDate *fireDate = [NSDate dateWithTimeIntervalSinceNow:3];
    
    notification.fireDate = fireDate;
    // 时区
    notification.timeZone = [NSTimeZone defaultTimeZone];
    
    // 通知内容
    notification.alertBody = alertBody;
    notification.applicationIconBadgeNumber++;
    // 通知被触发时播放的声音
    notification.soundName = UILocalNotificationDefaultSoundName;
    // 通知参数
    notification.userInfo = userDict;
    
    //请求本地通知 授权
    [self getRequestWithLocalNotificationSleep:notification];
}
 
- (void)getRequestWithLocalNotificationSleep:(UILocalNotification *)notification
{
    // ios8后,需要添加这个注册,才能得到授权
    if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
        UIUserNotificationType type =  UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound;
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:type categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
    }
    
    [[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
 
/**
 tabBarItem的字体颜色设置
 */
-(void)setTabBarItemFontColor {
    // 字体颜色 (选中)
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:12.0F], NSForegroundColorAttributeName : YTHColor(229, 0, 92)} forState:UIControlStateSelected];
    
    // 字体颜色 (未选中)
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:12.0F],  NSForegroundColorAttributeName:YTHColor(139, 139, 139)} forState:UIControlStateNormal];
}
 
/**
 配置
 */
-(void)Configuration {
    //设置状态栏的颜色
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
    
    //防止横屏时,状态栏被隐藏
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
    
    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
    
    //去黑线
    [[UINavigationBar appearance]  setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
    
}
 
/**
 *  配置客户端信息
 */
-(void)getInfoFromCompany {
    //判断之前是否缓存了用户信息
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if ([fileManager fileExistsAtPath:USERINFOfILE]){
        NSDictionary *userInfo=[NSKeyedUnarchiver unarchiveObjectWithData:[NSData dataWithContentsOfFile:USERINFOfILE]];
        [[NSUserDefaults standardUserDefaults] setObject:[userInfo objectForKey:@"id"] forKey:@"userId"];
        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"newUser"];
    }else{
        //没有缓存用户信息,说明这是一个全新的用户
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"newUser"];
    }
    
    [[YTHNetInterface startInterface] getSystemClientParamsWithblock:^(BOOL isSuccessful, id result, NSString *error) {
        if (isSuccessful) {
            NSUserDefaults *uid = [NSUserDefaults standardUserDefaults];
            NSArray *tempArr=[[result objectForKey:@"data"] objectForKey:@"systemClientParamsList"];
            for (int i=0; i<tempArr.count; i++) {
                NSDictionary *tempDic=tempArr[i];
                [uid setObject:[tempDic objectForKey:@"value"] forKey:[tempDic objectForKey:@"key"]];
            }
            [uid synchronize];
        }else{
            
        }
    }];
}
 
#pragma mark 阿里百川
-(void)setAliTrade {
    // 百川平台基础SDK初始化,加载并初始化各个业务能力插件
    [[AlibcTradeSDK sharedInstance] asyncInitWithSuccess:^{
        NSLog(@"成功");
    } failure:^(NSError *error) {
        NSLog(@"Init failed: %@", error.description);
    }];
    
    // 开发阶段打开日志开关,方便排查错误信息
    //默认调试模式打开日志,release关闭,可以不调用下面的函数
    [[AlibcTradeSDK sharedInstance] setDebugLogOpen:YES];
    
    // 配置全局的淘客参数
    //如果没有阿里妈妈的淘客账号,setTaokeParams函数需要调用
    AlibcTradeTaokeParams *taokeParams = [[AlibcTradeTaokeParams alloc] init];
    taokeParams.pid = FanLi_Pid; //mm_XXXXX为你自己申请的阿里妈妈淘客pid
    taokeParams.adzoneId = FanLi_adzoneId;
    taokeParams.extParams=@{@"taokeAppkey":@"24838852"};
    
    [[AlibcTradeSDK sharedInstance] setTaokeParams:taokeParams];
    
    // 设置全局配置,是否强制使用h5
    [[AlibcTradeSDK sharedInstance] setIsForceH5:NO];
}
 
/**
 注册推送
 */
- (void)registerAPNS {
    float sysVer = [[[UIDevice currentDevice] systemVersion] floatValue];
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
    if (sysVer >= 10) {
        // iOS 10
        [self registerPush10];
    } else if (sysVer >= 8) {
        // iOS 8-9
        [self registerPush8to9];
    } else {
        // before iOS 8
        [self registerPushBefore8];
    }
#else
    if (sysVer < 8) {
        // before iOS 8
        [self registerPushBefore8];
    } else {
        // iOS 8-9
        [self registerPush8to9];
    }
#endif
}
 
/**
 iOS10注册通知的方法
 */
- (void)registerPush10 {
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    center.delegate = self;
    
    [center requestAuthorizationWithOptions:UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert completionHandler:^(BOOL granted, NSError * _Nullable error) {
        if (granted) {
        }
    }];
    
    [[UIApplication sharedApplication] registerForRemoteNotifications];
#endif
}
 
/**
 iOS8,9注册通知的方法
 */
- (void)registerPush8to9 {
    UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
    UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
    [[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
}
/**
 iOS8之前的注册通知方法
 */
- (void)registerPushBefore8 {
#if __IPHONE_OS_VERSION_MAX_ALLOWED <= __IPHONE_8_0
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
#endif
}
 
#pragma mark -UITabBarControllerDelegate
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    [[NSNotificationCenter defaultCenter] postNotificationName:@"HomeViewController" object:nil userInfo:nil];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"DynamicViewController" object:nil userInfo:nil];
}
 
#pragma mark 友盟相关
- (void)setUmeng {
 
    [UMConfigure initWithAppkey:UmengKey channel:nil];
    [MobClick setScenarioType:E_UM_NORMAL];
 
    //友盟分享
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:@"wx5c0d167c6e3ad726" appSecret:@"0c79d5869bb0f2d7c13e43f9a18f440d" redirectURL:nil];//微信
    
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_QQ appKey:@"1106259063" appSecret:nil redirectURL:@"http://mobile.umeng.com/social"];//QQ
    
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Sina appKey:@"3403499693"  appSecret:@"aa1c7b53c4d34b634dcc6c1ed36f48ce" redirectURL:@"https://sns.whalecloud.com/sina2/callback"];//新浪
    
}
 
-(void)netWorkChangeEvent {
    
    [[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES];
    NSURL *url = [NSURL URLWithString:@"http://baidu.com"];
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithBaseURL:url];
    [manager.reachabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        self.netWorkStatesCode = status;
        switch (status) {
            case AFNetworkReachabilityStatusReachableViaWWAN:
                NSLog(@"当前使用的是流量模式");
                break;
            case AFNetworkReachabilityStatusReachableViaWiFi:
                NSLog(@"当前使用的是wifi模式");
                break;
            case AFNetworkReachabilityStatusNotReachable:
                NSLog(@"断网了");
                break;
            case AFNetworkReachabilityStatusUnknown:
                NSLog(@"变成了未知网络状态");
                break;
                
            default:
                break;
        }
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"netWorkChangeEventNotification" object:@(status)];
    }];
    
    [manager.reachabilityManager startMonitoring];
}
 
#pragma mark -WXApiDelegate
-(void)onReq:(BaseReq*)req {
    //onReq是微信终端向第三方程序发起请求,要求第三方程序响应。第三方程序响应完后必须调用sendRsp返回。在调用sendRsp返回时,会切回到微信终端程序界面。
    NSLog(@"%@",req);
    
}
#pragma mark 微信登录的唯一入口
- (void)getUserInfoResponse:(APIResponse*) response {
    //    NSDictionary *dic = @{@"appid":@""};
}
-(void)onResp:(BaseResp*)resp {
    
    SendAuthResp *rep = (SendAuthResp *)resp;
    
    if (rep.errCode == 0) {//登录成功
        
        if ([YTHsharedManger startManger].isChangeWX) {
            
            [self changeWXWithCode:rep.code];
            
            [YTHsharedManger startManger].isChangeWX = NO;
            
            return;
        }
        
        [SVProgressHUD setContainerView:[UIApplication sharedApplication].delegate.window];
        [SVProgressHUD showWithStatus:@"微信绑定中"];
        
        if([[NSUserDefaults standardUserDefaults] objectForKey:@"userId"]) {//uid已经存在,说明是绑定操作
            
            [[YTHsharedManger startManger] bindUid:[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"]
                                     WithLoginType:@"2"
                                        WithOpenid:nil
                                        WithWXCode:rep.code
                                        WithTBName:nil block:^(BOOL isSuccessful, NSDictionary *dic) {
                                            
                                            if (isSuccessful) {
                                                
                                                [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"WeChatLogin"];
                                                
                                                [SVProgressHUD setContainerView:[UIApplication sharedApplication].delegate.window];
                                                [SVProgressHUD showSuccessWithStatus:BIND_SUCCESS];
                                                
                                                [[NSNotificationCenter defaultCenter] postNotificationName:@"WeChatReload" object:nil];
                                                
                                            } else {
                                                
                                                [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WeChatLogin"];
                                        
                                                [[NSNotificationCenter defaultCenter] postNotificationName:@"WeChatReload" object:nil];
                                            }
                                        }];
        } else {
            
            if ([YTHsharedManger startManger].isBound) {
                
                [[YTHsharedManger startManger] LogInForFanliQuanWithLoginType:@"2" WithWXCode:rep.code  create:@"2" uid:@"0" isfirst:[YTHsharedManger startManger].isfirst block:^(BOOL isSuccessful, NSDictionary *dic) {
                    
                    if (isSuccessful) {
                        
                        NSMutableDictionary *tempDic=[NSMutableDictionary dictionaryWithCapacity:0];
                        
                        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"WeChatLogin"];
                        [tempDic setObject:@"1" forKey:@"isSuccessful"];
                        
                        [SVProgressHUD setContainerView:[UIApplication sharedApplication].delegate.window];
                        [SVProgressHUD showSuccessWithStatus:BIND_SUCCESS];
                        
                        if ([YTHsharedManger startManger].isMessageLogin) {
                            
                            [[NSNotificationCenter defaultCenter] postNotificationName:@"PostWeChatLoginMessage" object:tempDic];
                            
                        } else {
                            
                              [[NSNotificationCenter defaultCenter] postNotificationName:@"PostWeChatLogin" object:tempDic];
                        }
                    
                    } else {
                        
                        NSMutableDictionary *tempDic = [NSMutableDictionary dictionaryWithCapacity:0];
                        
                        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WeChatLogin"];
                        [tempDic setObject:@"0" forKey:@"isSuccessful"];
                        
                        [SVProgressHUD setContainerView:[UIApplication sharedApplication].delegate.window];
                        [SVProgressHUD showErrorWithStatus:BIND_FAIL];
                        
                        [[NSNotificationCenter defaultCenter] postNotificationName:@"PostWeChatLogin" object:tempDic];
                    }
                }];
                
            } else {
                
                [SVProgressHUD setContainerView:[UIApplication sharedApplication].delegate.window];
                [SVProgressHUD showWithStatus:@"正在为你登录..."];
                
                [[YTHsharedManger startManger] LogInForFanliQuanWithLoginType:@"2" WithWXCode:rep.code  create:@"0" uid:@"0" isfirst:[YTHsharedManger startManger].isfirst block:^(BOOL isSuccessful, NSDictionary *dic) {
                    
                    if (isSuccessful) {
                        
                        NSMutableDictionary *tempDic=[NSMutableDictionary dictionaryWithCapacity:0];
                        
                        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"WeChatLogin"];
                        [tempDic setObject:@"1" forKey:@"isSuccessful"];
                        
                        [SVProgressHUD setContainerView:[UIApplication sharedApplication].delegate.window];
                        [SVProgressHUD showSuccessWithStatus:LOGIN_SUCCESS];
                        
                        [[NSNotificationCenter defaultCenter] postNotificationName:@"PostWeChatLogin" object:tempDic];
 
                    } else {
                        
                        NSMutableDictionary *tempDic=[NSMutableDictionary dictionaryWithCapacity:0];
                        
                        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WeChatLogin"];
                        [tempDic setObject:@"0" forKey:@"isSuccessful"];
                        
                        [SVProgressHUD setContainerView:[UIApplication sharedApplication].delegate.window];
                        [SVProgressHUD showErrorWithStatus:LOGIN_FAIL];
                        
                        [[NSNotificationCenter defaultCenter] postNotificationName:@"PostWeChatLogin" object:tempDic];
                    }
                }];
            }
        }
    }
}
 
- (void)changeWXWithCode:(NSString *)code {
    
    NSDictionary *dic = [[NSMutableDictionary alloc] init];
    
    [dic setValue:code forKey:@"code"];
    [dic setValue:[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"] forKey:@"uid"];
    
    [JYNetWorking Post:[NSString stringWithFormat:@"%@/%@",domainHTTP,@"/user/changeWX"] param:dic success:^(NSDictionary *object) {
        
        if ([object[@"code"]integerValue] == 0) {
            
            [SVProgressHUD setContainerView:[UIApplication sharedApplication].delegate.window];
            [SVProgressHUD showSuccessWithStatus:BIND_CHANGE_SUCCESS];
            
            [[NSNotificationCenter defaultCenter] postNotificationName:@"PostWeChatLogin" object:object[@"data"][@"user"]];
            
        } else {
            
            [SVProgressHUD setContainerView:[UIApplication sharedApplication].delegate.window];
            [SVProgressHUD showSuccessWithStatus:object[@"msg"]];
        }
        
    } fail:^(id object) {
        
        [SVProgressHUD showSuccessWithStatus:object];
    }];
}
 
-(void)dealloc {
    
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:@"netWorkChangeEventNotification"
                                                  object:nil];
}
 
@end