// // AppDelegate+ThirdParty.m // GIGA // // Created by lianxiang on 2018/8/16. // Copyright © 2018年 com.giga.ios. All rights reserved. // #import "AppDelegate+ThirdParty.h" #define PUSH_APPKEY @"1f8122badd24c2adb8b3f231" #import "WXApi.h" #import #import #import #define UMAPP_Key @"5b83a929b27b0a1b9e000036" @implementation AppDelegate (ThirdParty) -(void)configThridPartyWithOptions:(NSDictionary *)launchOptions{ //极光推送 //APNS Regist [UIApplication sharedApplication].applicationIconBadgeNumber = 0; [JPUSHService resetBadge]; JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init]; entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound; if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) { // 可以添加自定义categories // NSSet *categories for iOS10 or later // NSSet *categories for iOS8 and iOS9 } [JPUSHService registerForRemoteNotificationConfig:entity delegate:self]; // Required // init Push [JPUSHService setupWithOption:launchOptions appKey:PUSH_APPKEY channel:@"App store" apsForProduction:GIGA_PUSH_ENVIRONMENT advertisingIdentifier:nil]; //微信 [WXApi registerApp:WXin_APPID]; [WXApi startLogByLevel:WXLogLevelDetail logBlock:^(NSString *log) { NSLog(@"%@",log); }]; //bugly [Bugly startWithAppId:nil]; //友盟统计 [UMConfigure setEncryptEnabled:YES]; [UMConfigure setLogEnabled:YES]; [UMConfigure initWithAppkey:UMAPP_Key channel:nil]; // NSString* deviceID = [UMConfigure deviceIDForIntegration]; // NSLog(@"集成测试的deviceID:%@",deviceID); } #pragma mark 微信 - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options { return [WXApi handleOpenURL:url delegate:self]; } //WXApiDelegate - (void)onReq:(BaseReq *)req{ } - (void)onResp:(BaseResp *)resp{ NSLog(@"resp:%d",resp.errCode); if ([resp isKindOfClass:[SendAuthResp class]]) { SendAuthResp*rep = (SendAuthResp*)resp; if (resp.errCode == 0) { NC_POST_NAME_OBJECT(kWeiXinAuthrization_Success, @{@"code":rep.code}) }else{ [[UIApplication sharedApplication].keyWindow makeToast:@"授权失败" duration:1.6 position:CSToastPositionCenter]; } }else if ([resp isKindOfClass:[SendMessageToWXResp class]]){ //cancel事件和success事件将统一为success事件。 微信团队 //2018年08月13日 !!! //App 分享功能调整 if (resp.errCode == WXSuccess) { GILog(@"分享取消或成功"); NC_POST_NAME_OBJECT(NC_UseShareSuccessNoti, nil); }else if (resp.errCode == WXErrCodeUserCancel){ GILog(@"分享取消"); } } } #pragma mark - 远程推送 // ios 10 Support - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler API_AVAILABLE(ios(10.0)){ [UIApplication sharedApplication].applicationIconBadgeNumber = 0; [JPUSHService resetBadge]; // Required NSDictionary * userInfo = response.notification.request.content.userInfo; GILog(@"ios(10.0)-userInfo%@",userInfo); if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) { [JPUSHService handleRemoteNotification:userInfo]; } completionHandler(); // 系统要求执行这个方法 } - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler API_AVAILABLE(ios(10.0)){ // Required NSDictionary * userInfo = notification.request.content.userInfo; //GILog(@"userInfo%@",userInfo); if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) { [JPUSHService handleRemoteNotification:userInfo]; } completionHandler(UNNotificationPresentationOptionAlert|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionBadge); // 需要执行这个方法,选择是否提醒用户,有Badge、Sound、Alert三种类型可以选择设置 } -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{ [JPUSHService registerDeviceToken:deviceToken]; } - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { //Optional NSLog(@"did Fail To Register For Remote Notifications With Error: %@", error); } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { [UIApplication sharedApplication].applicationIconBadgeNumber = 0; [JPUSHService resetBadge]; // Required, iOS 7 Support GILog(@"iOS 7 userInfo%@",userInfo); [JPUSHService handleRemoteNotification:userInfo]; completionHandler(UIBackgroundFetchResultNewData); } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { [UIApplication sharedApplication].applicationIconBadgeNumber = 0; [JPUSHService resetBadge]; // Required,For systems with less than or equal to iOS6 [JPUSHService handleRemoteNotification:userInfo]; } @end