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、生产上的使用

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

      还款记录仪

      

  • 相关阅读:
    jQuery 请指出'$'和'$.fn'的区别?或者说出'$.fn'的用途。
    ie8及其以下浏览器的document.getElementsByClassName兼容性问题
    document.all的详细解释(document.all基本上所有浏览器可用!)
    CSS浮动属性Float介绍
    JCarouselLite--帮助文档
    css定位之z-index问题分析
    Android手机同步电脑端google chrome书签
    AWK原理及命令和文件输入
    Sed命令
    Shell正则表达式
  • 原文地址:https://www.cnblogs.com/yrcn/p/7412191.html
Copyright © 2011-2022 走看看