Ios 如何在AppDelegate中扩展UNUserNotificationCenterDelegate协议?
我正在开发一个React本机应用程序,它使用两个不同的库来处理本地通知(Ios 如何在AppDelegate中扩展UNUserNotificationCenterDelegate协议?,ios,objective-c,react-native,push-notification,leanplum,Ios,Objective C,React Native,Push Notification,Leanplum,我正在开发一个React本机应用程序,它使用两个不同的库来处理本地通知(React本机社区/推送通知ios)和远程推送通知(Leanplum)。Leanplum SDK使用swizzling。不幸的是,即使我禁用swizzling,建议的显示前台通知的设置也会阻止正确处理远程通知 我收到了远程通知SDK支持团队的一条反馈 您在本地级别的实现正在干扰Leanplum swizzle。您是否能够实现用户通知委托协议,并在app delegate类中进行扩展?在iOS实现中,这允许两种逻辑(LP和lo
React本机社区/推送通知ios
)和远程推送通知(Leanplum)。Leanplum SDK使用swizzling。不幸的是,即使我禁用swizzling,建议的显示前台通知的设置也会阻止正确处理远程通知
我收到了远程通知SDK支持团队的一条反馈
您在本地级别的实现正在干扰Leanplum swizzle。您是否能够实现用户通知委托协议,并在app delegate类中进行扩展?在iOS实现中,这允许两种逻辑(LP和local)自动且平滑地进行。我们建议AppDelegate实现扩展UnuseNotificationCenterDelegate协议,特别是如果您希望保留本地推送实现
虽然我正在尽我最大的努力尽快学习Objective-C,但我不是本地的iOS开发人员,我不知道如何遵循这个建议。我已经阅读了很多关于设置推送通知的问题,但是他们都建议使用下面的设置,我还没有找到任何解决前台通知处理干扰另一个库的问题的方法
如何扩展AppDelegate中的UNUserNotificationCenterDelegate
协议,以不干扰远程通知库的方式处理前台通知
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[...]
// Define UNUserNotificationCenter
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self; // <-- interferes with the remote notification SDK
[RNSplashScreen show];
return YES;
}
[...]
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
[RNCPushNotificationIOS didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
// Needs to be called if swizzling is disabled in Info.plist otherwise it won’t affect SDK if swizzling is enabled.
[Leanplum didReceiveRemoteNotification:userInfo
fetchCompletionHandler:completionHandler];
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
// Needs to be called if swizzling is disabled in Info.plist otherwise it won’t affect SDK if swizzling is enabled.
[RNCPushNotificationIOS didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
[Leanplum didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
[RNCPushNotificationIOS didFailToRegisterForRemoteNotificationsWithError:error];
// Needs to be called if swizzling is disabled in Info.plist otherwise it won’t affect SDK if swizzling is enabled.
[Leanplum didFailToRegisterForRemoteNotificationsWithError:error];
}
// Required for localNotification event
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)(void))completionHandler
{
[RNCPushNotificationIOS didReceiveNotificationResponse:response];
}
//Called when a notification is delivered to a foreground app.
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge);
}
-(BOOL)应用程序:(UIApplication*)应用程序使用选项完成启动:(NSDictionary*)启动选项
{
[...]
//定义未使用的通知中心
UNUserNotificationCenter*中心=[UNUserNotificationCenter currentNotificationCenter];
center.delegate=self;//我也遇到了同样的问题,但我发现在停用swizzling时不再调用某些深层代码
将此添加到文件的顶部
#导入
替换
-(void)用户通知中心:(UNUserNotificationCenter*)中心将使用completionHandler:(void(^)(UNNotificationPresentationOptions))completionHandler显示通知:(UNNotification*)通知
{
完成处理程序(UNNotificationPresentationOptionSound | UnnotificationPresentationOptionErt | UNNotificationPresentationOptionBadge);
}
为此:
-(void)用户通知中心:(UNUserNotificationCenter*)中心将使用completionHandler:(void(^)(UNNotificationPresentationOptions))completionHandler显示通知:(UNNotification*)通知
{
[[LPPushNotificationsManager sharedManager].handler将显示通知:带有completionHandler:completionHandler的通知];
}
我也面临同样的问题,但我发现在停用swizzling时不再调用某些深层代码
将此添加到文件的顶部
#导入
替换
-(void)用户通知中心:(UNUserNotificationCenter*)中心将使用completionHandler:(void(^)(UNNotificationPresentationOptions))completionHandler显示通知:(UNNotification*)通知
{
完成处理程序(UNNotificationPresentationOptionSound | UnnotificationPresentationOptionErt | UNNotificationPresentationOptionBadge);
}
为此:
-(void)用户通知中心:(UNUserNotificationCenter*)中心将使用completionHandler:(void(^)(UNNotificationPresentationOptions))completionHandler显示通知:(UNNotification*)通知
{
[[LPPushNotificationsManager sharedManager].handler将显示通知:带有completionHandler:completionHandler的通知];
}
// Define UNUserNotificationCenter
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self; // <-- interferes with the remote notification SDK
...
//Called when a notification is delivered to a foreground app.
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge);
}