pod ‘JPush’添加Framework
CFNetwork.framework
CoreFoundation.framework
CoreTelephony.framework
SystemConfiguration.framework
CoreGraphics.framework
Foundation.framework
UIKit.framework
Security.framework
libz.tbd (Xcode7以下版本是libz.dylib)
AdSupport.framework (獲取IDFA需要;如果不使用IDFA,請不要添加)
UserNotifications.framework (Xcode8及以上)
libresolv.tbd (JPush 2.2.0及以上版本需要, Xcode7以下版本是libresolv.dylib)
AppDelegate.m代碼
#import <JPUSHService.h>
#ifdef NSFoundationVersionNumber_iOS_9_x_Max
#import <UserNotifications/UserNotifications.h>
#endif
@interface AppDelegate ()<JPUSHRegisterDelegate>- (
BOOL)application:(
UIApplication *)application didFinishLaunchingWithOptions:(
NSDictionary *)launchOptions {[
self registerRemoteNotification];
if([jgAPNSForProduction isEqualToString:@
"0"]){[JPUSHService setupWithOption:launchOptions appKey:jgAppKeychannel:@
"App Store"apsForProduction:
NOadvertisingIdentifier:
nil];}
else{[JPUSHService setupWithOption:launchOptions appKey:jgAppKeychannel:@
"App Store"apsForProduction:
YESadvertisingIdentifier:
nil];}[[
NSNotificationCenter defaultCenter] addObserver:
self selector:
@selector(getRegistrationID:) name:kJPFNetworkDidLoginNotification object:
nil];[[
NSNotificationCenter defaultCenter] addObserver:
self selector:
@selector(networkDidReceiveMessage:) name:kJPFNetworkDidReceiveMessageNotification object:
nil];}
- (
void)registerRemoteNotification {
if ([[UIDevice currentDevice]
.systemVersion floatValue] >=
10.0) {JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];entity
.types = UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound;[JPUSHService registerForRemoteNotificationConfig:entity delegate:
self];}
else if ([[UIDevice currentDevice]
.systemVersion floatValue] >=
8.0) {[JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |UIUserNotificationTypeSound |UIUserNotificationTypeAlert)categories:
nil];}
else {[JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound |UIRemoteNotificationTypeAlert)categories:
nil];
}
-(
void)getRegistrationID:(
NSNotification *)notification
{
NSString *registrationID=[JPUSHService registrationID];
}
- (
void)networkDidReceiveMessage:(
NSNotification *)notification{
}
- (
void)application:(
UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {[JPUSHService registerDeviceToken:deviceToken];
}
- (
void)application:(
UIApplication *)application didReceiveRemoteNotification:(
NSDictionary *)userInfo {[JPUSHService handleRemoteNotification:userInfo];
}- (
void)application:(
UIApplication *)application didReceiveRemoteNotification:(
NSDictionary *)userInfo fetchCompletionHandler:(
void (^)(UIBackgroundFetchResult))completionHandler {[JPUSHService handleRemoteNotification:userInfo];completionHandler(UIBackgroundFetchResultNewData);
}
#pragma mark- JPUSHRegisterDelegate
- (
void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(
void (^)(
NSInteger))completionHandler {
NSDictionary * userInfo = notification
.request.content.userInfo;
if([notification
.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {[JPUSHService handleRemoteNotification:userInfo];}completionHandler(UNNotificationPresentationOptionAlert);
}
- (
void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(
void (^)())completionHandler {
NSDictionary * userInfo = response
.notification.request.content.userInfo;
if([response
.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {[JPUSHService handleRemoteNotification:userInfo];}completionHandler();
}
總結
以上是生活随笔為你收集整理的iOS开发(第三方使用)——极光推送SDK接入的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。