iOS 前台时的推送弹窗效果

具体代码:参看以下demo

Github: https://github.com/Yasashi/EBForeNotification

具体操作如下:

   1、将EBForeNotification文件夹添加进入工程中

   2、targets --> Build Settings --> 搜 other link --> 添加 -ObjC

   3、本地弹窗

        

//普通弹窗(系统声音)
[EBForeNotification handleRemoteNotification:@{@"aps":@{@"alert":@"展示内容"}} soundID:1312];

//普通弹窗(指定声音文件)
[EBForeNotification handleRemoteNotification:@{@"aps":@{@"alert":@"展示内容"}} customSound:@"my_sound.wav"];

//带自定义参数的弹窗(系统声音)
[EBForeNotification handleRemoteNotification:@{@"aps":@{@"alert":@"展示内容"}, @"key1":@"value1", @"key2":@"value2"} soundID:1312];

//普通弹窗(指定声音文件)
[EBForeNotification handleRemoteNotification:@{@"aps":@{@"alert":@"展示内容"}, @"key1":@"value1", @"key2":@"value2"} customSound:@"my_sound.wav"];
...}

      4、接受远程、本地推送弹窗

 

//ios7 before
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { 
    ...
    //系统声音弹窗
    [EBForeNotification handleRemoteNotification:userInfo soundID:1312];

    //指定声音文件弹窗
    [EBForeNotification handleRemoteNotification:userInfo customSound:@"my_sound.wav"];
    ...
}

//ios7 later  
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {    
    ...
    //系统声音弹窗
    [EBForeNotification handleRemoteNotification:userInfo soundID:1312];

    //指定声音文件弹窗
    [EBForeNotification handleRemoteNotification:userInfo customSound:@"my_sound.wav"];
    ...
    completionHandler(UIBackgroundFetchResultNewData);
}

              注明:soundID 参数:iOS 系统自带的声音 id,系统级的推送服务默认使用的是三全音,id = 1312,其他系统声音 id 可以在这里查询到 iOS Predefined sounds备用地址 AudioServices sounds

              5、添加 Observer 监听 EBBannerViewDidClick,获取推送内容,通过推送时自定义的字段处理自己逻辑,如:跳转到对应页面等。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(eBBannerViewDidClick:) name:EBBannerViewDidClick object:nil];
-(void)eBBannerViewDidClick:(NSNotification*)noti{
    if(noti[@"key1" == @"跳转页面1"]){
        //跳转到页面1
    }
}

 

     

转载于:https://www.cnblogs.com/angongIT/p/5725084.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值