本地推送,远程推送(JPUSHService极光推送例)

来源:互联网 发布:js onclick传两个参数 编辑:程序博客网 时间:2024/06/05 12:42

本地推送,例: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";

staticBOOL isProduction = FALSE;


@interface AppDelegate ()


@end


@implementation AppDelegate



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    

    //注册远程推送

    if ([[UIDevicecurrentDevice].systemVersionfloatValue] >= 8.0) {

        //可以添加自定义categories

        [JPUSHServiceregisterForRemoteNotificationTypes:(UIUserNotificationTypeBadge |

                                                         UIUserNotificationTypeSound |

                                                         UIUserNotificationTypeAlert)

                                             categories:nil];

    }else {

        //categories 必须为nil

        [JPUSHServiceregisterForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |

                                                         UIRemoteNotificationTypeSound |

                                                         UIRemoteNotificationTypeAlert)

                                             categories:nil];

    }

    

    [JPUSHServicesetupWithOption:launchOptions appKey:appKey

                         channel:channelapsForProduction:isProduction];

    return YES;

}


//将令牌传送给极光推送服务器

- (void)application:(UIApplication *)application

didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

       [JPUSHServiceregisterDeviceToken:deviceToken];

}


- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{

    [JPUSHServicehandleRemoteNotification:userInfo];

   NSLog(@"收到通知");

}


//已经接收到远程推送

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {

    

    [JPUSHServicehandleRemoteNotification:userInfo];

    completionHandler(UIBackgroundFetchResultNewData);

}


0 0