因業務需求,使用RN開發的APP須要支持本地通知,因而研究了一下;自己想找個造好的輪子(react-native-push-notification),可是她對IOS不處理,讓IOS使用PushNotificationIOS。javascript
//取消指定的本地通知 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{ } }
使用PushNotificationIOS.cancelLocalNotifications(userInfo);方法,可是須要本地通知對象的userInfo屬性。java
感興趣的朋友能夠掃碼下載看看。react