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
        }
    }
    

         

  • 相关阅读:
    [转]暴风电视开机卡死、闪屏怎么办
    暴风电视快速查询机器型号及平台
    暴风电视风行系统FUNOS插入U盘、移动硬盘不能写入文件。
    yum版本号前有:冒号 指的是依赖版本号,默认0不显示
    yum多个源repo安装指定版本docker
    [转]YUM的工作机制与配置
    yum!base仓库里的repo id(源标识)前有叹号
    Docker新旧版本号下载
    yum没有可用软件包 docker。错误:无须任何处理CentOS-Media.repo仓库
    【笔记整理】之 servlet
  • 原文地址:https://www.cnblogs.com/angongIT/p/5725084.html
Copyright © 2011-2022 走看看