fli*_*hip 0 objective-c push-notification react-native
当应用程序在前台运行时,是否可以触发横幅推送通知的显示,就像它在后台一样?
我正在使用React-Native版本41.2和react-native-push-notification 2.2.1
我在搜索中注意到,通过在AppDelegate中添加以下内容,iOs 10应该是可能的:
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{
completionHandler(UNNotificationPresentationOptionAlert);
}
Run Code Online (Sandbox Code Playgroud)
但是,这似乎没有被击中,而是正在点击didReceiveLocalNotification方法,如下所示:
// Required for the localNotification event.
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
[RCTPushNotificationManager didReceiveLocalNotification:notification];
}
Run Code Online (Sandbox Code Playgroud)
React-Native是否可以访问userNotificationCenter?或者是否可以使用其他方法获得类似的结果?
谢谢.
以下是我设法让这个工作的方法.
在该AppDelegate.h文件中,您需要导入UserNotifications并设置UNUserNotificationCenterDelegate,如下所示:
#import <UIKit/UIKit.h>
#import <UserNotifications/UserNotifications.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate, UNUserNotificationCenterDelegate>
Run Code Online (Sandbox Code Playgroud)
然后在AppDelegate.m文件中,您需要[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];在didFinishLaunchingWithOptions方法中添加内容.
然后你必须删除didReceiveLocalNotification和didReceiveRemoteNotification,因为它们似乎优先于userNotificationCenter.
然后添加userNotificationCenter处理程序,如下所示.
- (void)userNotificationCenter:(UNUserNotificationCenter* )center willPresentNotification:(UNNotification* )notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
completionHandler(UNNotificationPresentationOptionAlert);
}
Run Code Online (Sandbox Code Playgroud)
希望这能帮助其他一些反应原生的开发人员像我一样不熟悉iOs开发.
| 归档时间: |
|
| 查看次数: |
1620 次 |
| 最近记录: |