zoukankan      html  css  js  c++  java
  • React Native 插件系列之PushNotificationIOS

    1、背景

      因业务需求,使用RN开发的APP需要支持本地通知,于是研究了一下;本身想找个造好的轮子(react-native-push-notification),但是她对IOS不处理,让IOS使用PushNotificationIOS。

    2、主要代码

      //取消指定的本地通知
        static noti_cancelLocalNotifications(userInfo){
            if(YrcnApp.Platform.isIOS){
                PushNotificationIOS.cancelLocalNotifications(userInfo);
            }else{
    
            }
        }
        //取消所有本地通知
        static noti_cancelAllLocalNotifications(){
            if(YrcnApp.Platform.isIOS){
                PushNotificationIOS.cancelAllLocalNotifications();
            }else{
    
            }
        }
        //检查本地通知的权限并请求授权
        static noti_checkPermissions(succCallback){
            if(YrcnApp.Platform.isIOS){
                PushNotificationIOS.checkPermissions(function(checkPermissionsObj){
                    if(checkPermissionsObj.alert == "0"){
                        PushNotificationIOS.requestPermissions({alert:"1",badge:"1",sound:"1"});
                    }
                    succCallback();
                });
            }else{
    
            }
        }
        //设置本地通知
        static noti_scheduleLocalNotification(obj){
            if(YrcnApp.Platform.isIOS){
                PushNotificationIOS.scheduleLocalNotification(obj);
            }else{
    
            }
        }
        //获取本地所有通知数组
        static noti_getScheduledLocalNotifications(succCallback){
            if(YrcnApp.Platform.isIOS){
                PushNotificationIOS.getScheduledLocalNotifications(function(getScheduledLocalNotificationsObj){
                    succCallback(getScheduledLocalNotificationsObj);
                });
            }else{
    
            }
        }
    

    3、遇到的问题

      如何取消指定的通知?

      使用PushNotificationIOS.cancelLocalNotifications(userInfo);方法,但是需要本地通知对象的userInfo属性。

    4、生产上的使用

      感兴趣的朋友可以扫码下载看看。

      还款记录仪

      

  • 相关阅读:
    c语言指针讲解第一节初识指针
    linux的的一些入门常识
    sql手注的思路
    mysql主从备份配置
    CentOS 6.5 nginx+tomcat+ssl配置
    mysql 5.7.18安装教程
    minIO分布式集群搭建+nginx负载均衡
    Linux常用命令
    使用python连接mysql数据库——pymysql模块的使用
    with与上下文管理器
  • 原文地址:https://www.cnblogs.com/yrcn/p/7412191.html
Copyright © 2011-2022 走看看