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

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

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值