zoukankan      html  css  js  c++  java
  • 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
        }
    }
    

         

  • 相关阅读:
    《代码大全2》读书笔记 Week3
    华莱士 勇敢的心 值得一看的电影
    验证sqlserver 不区分大小写
    sql 分割函数
    子报表设置数据源 指定子报表数据 可以预防报表显示错误的问题
    linq 实现 tsql里的 in 和not in的功能
    水晶报表参数构建和数据传入显示函数
    .net 发邮件带附件源码
    将C#的dll文件反编译成il文件工具
    sp_executesql介绍和使用
  • 原文地址:https://www.cnblogs.com/angongIT/p/5725084.html
Copyright © 2011-2022 走看看