当用户打开应用程序但在文档中找不到方法时,我在react-native-push-notification中寻找重置 * 应用程序徽章编号 *,有什么想法吗?
eufgjt7s1#
https://facebook.github.io/react-native/docs/pushnotificationios.html#setapplicationiconbadgenumber
PushNotificationIOS.getApplicationIconBadgeNumber((num)=>{ // get current number if(num >= 1){ PushNotificationIOS.setApplicationIconBadgeNumber(0) //set number to 0 } });
PushNotificationIOS已从react本地导入
PushNotificationIOS
cyvaqqii2#
您可以将其添加到AppDelegate.m中,当应用打开或进入后台时,它会将徽章计数设置为0。
- (void)applicationDidBecomeActive:(UIApplication *)application{ [UIApplication sharedApplication].applicationIconBadgeNumber = 0; } -(void)applicationDidEnterBackground:(UIApplication *)application{ [UIApplication sharedApplication].applicationIconBadgeNumber = 0; }
或者在app.js中(如果使用react钩子),当应用程序处于活动状态或进入后台时,也将重置徽章计数
import { AppState } from 'react-native'; useEffect(() => { AppState.addEventListener("change", _handleAppStateChange); return () => { AppState.removeEventListener("change", _handleAppStateChange); }; }, []); const _handleAppStateChange = (nextAppState) => { if (Platform.OS === 'ios' && nextAppState === 'active' || nextAppState === 'background') { PushNotificationIOS.setApplicationIconBadgeNumber(0); } }
aiazj4mn3#
非常简单
import PushNotification from 'react-native-push-notification'; ... ... PushNotification.setApplicationIconBadgeNumber(0); //magic
3条答案
按热度按时间eufgjt7s1#
https://facebook.github.io/react-native/docs/pushnotificationios.html#setapplicationiconbadgenumber
PushNotificationIOS
已从react本地导入cyvaqqii2#
您可以将其添加到AppDelegate.m中,当应用打开或进入后台时,它会将徽章计数设置为0。
或者
在app.js中(如果使用react钩子),当应用程序处于活动状态或进入后台时,也将重置徽章计数
aiazj4mn3#
非常简单