如何控制Netmera ios sdk 提示Push notifications 权限?
How to control when Netmera ios sdk will prompt Push notifications permission?
我在我的应用程序中使用 Netmera SDK。它会在应用程序启动后立即提示用户允许推送通知。如何控制该行为并在用户登录我的应用程序后征求用户的许可?
添加或删除 [Netmera setApiKey:kNetmeraAPIKey];
行无效。
即使删除对 <Netmera/Netmera.h>
的所有依赖项也没有效果。
看起来 Netmera SDK 以某种方式注入调用 registerUserNotificationSettings:
方法……我不知道。
是否有任何解决方法可以解决这个问题?
目前没有一种简单的方法可以做到这一点。在下一个主要版本中,将会有更好的权限管理流程:)
但是,现在您可以执行以下操作:
添加类别声明到NMPushManager+DisablePushOnLaunchHack.h文件:
#import <Netmera/Netmera.h>
@interface NMPushManager (DisablePushOnLaunchHack)
@end
将类别实现添加到NMPushManager+DisablePushOnLaunchHack.m文件:
#import "NMPushManager+DisablePushOnLaunchHack.h"
@implementation NMPushManager (DisablePushOnLaunchHack)
+ (void)setEnabledUserNotificationTypesInternal:(UIUserNotificationType)type{
// Do nothing.
}
@end
最后,您应该将 #import "NMPushManager+DisablePushOnLaunchHack.h"
添加到您的 AppDelegate class 以防止 Netmera 自动注册推送通知。
之后,您可以随时使用以下代码向用户提示权限警报:
// You can set a different UIUserNotificationType combination
[NMPushManager setEnabledUserNotificationTypes:(UIUserNotificationTypeAlert |
UIUserNotificationTypeSound |
UIUserNotificationTypeBadge)];
我在我的应用程序中使用 Netmera SDK。它会在应用程序启动后立即提示用户允许推送通知。如何控制该行为并在用户登录我的应用程序后征求用户的许可?
添加或删除 [Netmera setApiKey:kNetmeraAPIKey];
行无效。
即使删除对 <Netmera/Netmera.h>
的所有依赖项也没有效果。
看起来 Netmera SDK 以某种方式注入调用 registerUserNotificationSettings:
方法……我不知道。
是否有任何解决方法可以解决这个问题?
目前没有一种简单的方法可以做到这一点。在下一个主要版本中,将会有更好的权限管理流程:)
但是,现在您可以执行以下操作:
添加类别声明到NMPushManager+DisablePushOnLaunchHack.h文件:
#import <Netmera/Netmera.h>
@interface NMPushManager (DisablePushOnLaunchHack)
@end
将类别实现添加到NMPushManager+DisablePushOnLaunchHack.m文件:
#import "NMPushManager+DisablePushOnLaunchHack.h"
@implementation NMPushManager (DisablePushOnLaunchHack)
+ (void)setEnabledUserNotificationTypesInternal:(UIUserNotificationType)type{
// Do nothing.
}
@end
最后,您应该将 #import "NMPushManager+DisablePushOnLaunchHack.h"
添加到您的 AppDelegate class 以防止 Netmera 自动注册推送通知。
之后,您可以随时使用以下代码向用户提示权限警报:
// You can set a different UIUserNotificationType combination
[NMPushManager setEnabledUserNotificationTypes:(UIUserNotificationTypeAlert |
UIUserNotificationTypeSound |
UIUserNotificationTypeBadge)];