Skip to content

Commit

Permalink
Compatible for Xcode7
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenYilong committed Oct 13, 2016
1 parent 39059a4 commit f155abc
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ @implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
application.applicationIconBadgeNumber = 0;
[self registerForRemoteNotification];
if ([[UIDevice currentDevice].systemVersion floatValue] < 10.0) {
// if (SYSTEM_VERSION_LESS_THAN(@"10.0")) {
if (SYSTEM_VERSION_LESS_THAN(@"10.0")) {
NSDictionary *remoteNotification = [self getRemoteNotificationFromLaunchOptions:launchOptions];
if (remoteNotification) {
//TODO:处理远程推送内容
Expand Down Expand Up @@ -117,6 +116,8 @@ - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotif
#pragma mark -
#pragma mark - UNUserNotificationCenterDelegate Method

#if XCODE_VERSION_GREATER_THAN_OR_EQUAL_TO_8

/**
* Required for iOS 10+
* 在前台收到推送内容, 执行的方法
Expand All @@ -140,7 +141,7 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)())completionHandler {
NSDictionary * userInfo = response.notification.request.content.userInfo;
NSDictionary *userInfo = response.notification.request.content.userInfo;
if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
//TODO:处理远程推送内容
NSLog(@"%@", userInfo);
Expand All @@ -149,6 +150,9 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
completionHandler(UNNotificationPresentationOptionBadge + UNNotificationPresentationOptionSound);
}


#endif

#pragma mark -
#pragma mark - UIApplicationDelegate Method

Expand All @@ -174,8 +178,10 @@ - (void)application:(UIApplication *)application
*/
- (void)registerForRemoteNotification {
// iOS 10 兼容
if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
// if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.0")) {
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.0")) {

#if XCODE_VERSION_GREATER_THAN_OR_EQUAL_TO_8

// 使用 UNUserNotificationCenter 来管理通知
UNUserNotificationCenter *uncenter = [UNUserNotificationCenter currentNotificationCenter];
// 监听回调事件
Expand All @@ -202,11 +208,13 @@ - (void)registerForRemoteNotification {
NSLog(@"已授权");
}
}];

#endif

}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
// else if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) {
else if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) {
UIUserNotificationType types = UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound;
Expand Down

0 comments on commit f155abc

Please sign in to comment.