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

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

  还款记录仪

  

原文地址:https://www.cnblogs.com/yrcn/p/7412191.html