110 lines
3.9 KiB
Objective-C
110 lines
3.9 KiB
Objective-C
//
|
||
// 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"
|
||
|
||
@implementation AppDelegate (ThirdParty)
|
||
|
||
-(void)configThridPartyWithOptions:(NSDictionary *)launchOptions{
|
||
|
||
//极光推送
|
||
//APNS Regist
|
||
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];
|
||
|
||
//微信
|
||
|
||
|
||
}
|
||
|
||
// 微信
|
||
- (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) {
|
||
[[NSNotificationCenter defaultCenter] postNotificationName: @"WXAuthSuccess" object:@{@"code":rep.code}];
|
||
|
||
}
|
||
}
|
||
}
|
||
// ios 10 Support
|
||
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler API_AVAILABLE(ios(10.0)){
|
||
|
||
// Required
|
||
NSDictionary * userInfo = response.notification.request.content.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;
|
||
if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
|
||
[JPUSHService handleRemoteNotification:userInfo];
|
||
}
|
||
completionHandler(UNNotificationPresentationOptionAlert); // 需要执行这个方法,选择是否提醒用户,有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);
|
||
}
|
||
|
||
//ios8 以下本应用可忽略
|
||
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
|
||
|
||
// Required, iOS 7 Support
|
||
[JPUSHService handleRemoteNotification:userInfo];
|
||
completionHandler(UIBackgroundFetchResultNewData);
|
||
}
|
||
|
||
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
|
||
|
||
// Required,For systems with less than or equal to iOS6
|
||
[JPUSHService handleRemoteNotification:userInfo];
|
||
}
|
||
|
||
|
||
|
||
@end
|