标签:
//
// JGPushHelp.h
// WYB
//
// Created by 淘元乐 on 15/7/29.
// Copyright (c) 2015年 China Model. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface JGPushHelp : NSObject
// 在应用启动的时候调用
+ (void)setupWithOptions:(NSDictionary *)launchOptions;
// 在appdelegate注册设备处调用
+ (void)registerDeviceToken:(NSData *)deviceToken;
// ios7以后,才有completion,否则传nil
+ (void)handleRemoteNotification:(NSDictionary *)userInfo completion:(void (^)(UIBackgroundFetchResult))completion;
// 显示本地通知在最前面
+ (void)showLocalNotificationAtFront:(UILocalNotification *)notification;
@end
//
// JGPushHelp.m
// WYB
//
// Created by 淘元乐 on 15/7/29.
// Copyright (c) 2015年 China Model. All rights reserved.
//
#import "JGPushHelp.h"
#import "APService.h"
@implementation JGPushHelp
+ (void)setupWithOptions:(NSDictionary *)launchOptions {
// Required
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1
// ios8之后可以自定义category
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
// 可以添加自定义categories
[APService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
UIUserNotificationTypeSound |
UIUserNotificationTypeAlert)
categories:nil];
} else {
#if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_8_0
// ios8之前 categories 必须为nil
[APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
#endif
}
#else
// categories 必须为nil
[APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
#endif
// Required
[APService setupWithOption:launchOptions];
return;
}
+ (void)registerDeviceToken:(NSData *)deviceToken {
[APService registerDeviceToken:deviceToken];
return;
}
+ (void)handleRemoteNotification:(NSDictionary *)userInfo completion:(void (^)(UIBackgroundFetchResult))completion {
[APService handleRemoteNotification:userInfo];
if (completion) {
completion(UIBackgroundFetchResultNewData);
}
return;
}
+ (void)showLocalNotificationAtFront:(UILocalNotification *)notification {
[APService showLocalNotificationAtFront:notification identifierKey:nil];
return;
}
@end
#import "JGPushHelp.h"
标签:
原文地址:http://www.cnblogs.com/zhuzhushen/p/4687707.html