本地推送,例:app闹钟,定时提醒==
/*
//iOS8以后需要先注册本地通知,需要经过用户的同意
if ([[UIDevice currentDevice].systemVersion doubleValue] >= 8.0) {
UIUserNotificationSettings *setting = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:setting];
}
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
//触发的时间
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];
//通知的内容
localNotification.alertBody = @"时间到了,该起床了";
//启动通知
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
//设置应用程序显示的徽标
[UIApplication sharedApplication].applicationIconBadgeNumber = 99;
*/
远程推送
例:
#import "AppDelegate.h"
#import "JPUSHService.h"
static NSString *appKey = @"18a57d31ebab4f9be6932d61";
static NSString *channel = @"Publish channel";
static BOOL isProduction = FALSE;
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//注册远程推送
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
//可以添加自定义categories
[JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
UIUserNotificationTypeSound |
UIUserNotificationTypeAlert)
categories:nil];
} else {
//categories 必须为nil
[JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
}
[JPUSHService setupWithOption:launchOptions appKey:appKey
channel:channel apsForProduction:isProduction];
return YES;
}
//将令牌传送给极光推送服务器
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[JPUSHService registerDeviceToken:deviceToken];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
[JPUSHService handleRemoteNotification:userInfo];
NSLog(@"收到通知");
}
//已经接收到远程推送
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
[JPUSHService handleRemoteNotification:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
}