GiGaMaskTime/GIGA/AppDelegate+ThirdParty.m

140 lines
5.1 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// 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 <Bugly/Bugly.h>
#import <UMCommon/UMCommon.h>
#import <UMAnalytics/MobClick.h>
#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<UNNotificationCategory *> *categories for iOS10 or later
// NSSet<UIUserNotificationCategory *> *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];
//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<UIApplicationOpenURLOptionsKey,id> *)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];
}
}
}
#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