追踪推送通知的用户选择[允许/不要] [英] track user choice for Push Notification [allow/don't]

查看:110
本文介绍了追踪推送通知的用户选择[允许/不要]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当应用程序需要注册推送通知(UIApplication registerForRemoteNotificationTypes)时,弹出窗口显示允许/不要选择。



 <$> 

因为解决方案: NSUInteger rntypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

很好,但是直到用户触摸某物



结果是,在我的EasyAPNS服务器中,大多数应用程序都在禁用模式,直到用户重新启动它们(因为第二次正确的配置将推送到我的服务器)。因此,第一次启动时,用户的真正选择可能没有考虑(如果你接受真的很快,在我的应用程序注册到EasyAPNS之前,你的选择反映在服务器上第一次启动)



有什么想法吗?

解决方案

似乎没有办法确定是否允许弹出已经显示过。我依靠用户默认值来跟踪这个:

   - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken: *)deviceToken 
{
BOOL didRegisterForPush = [[NSUserDefaults standardUserDefaults] boolForKey:@didRegisterForPush];
if(!didRegisterForPush){
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@didRegisterForPush];
[[NSUserDefaults standardUserDefaults] synchronize];
}
// ..发送deviceToken到服务器
}

现在您可以使用以下方法确定授权状态:

   - (PushAuthorizationStatus)pushAuthorizationStatus 
{
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if(types){
return kPushAuthorizationStatusAuthorized;
}
BOOL didRegisterForPush = [[NSUserDefaults standardUserDefaults] boolForKey:@didRegisterForPush];
if(didRegisterForPush){
return kPushAuthorizationStatusDenied;
}
return kPushAuthorizationStatusNotDetermined;
}

使用它可以发送 NotDetermined 状态到服务器,而不是拒绝


When an application need to register for push notification (UIApplication registerForRemoteNotificationTypes) a popup show Allow/Don't choice.

Is there a way to track when the user take this choice ?

Because the solution:

NSUInteger rntypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

is fine, but until the user touch something it's NO by default. I should only check this config after the user make a choice.

The consequence is that in my EasyAPNS server most of the application are in 'disabled' mode until the user relaunch them (because the second time the correct config will be pushed to my sever). So with the first launch the real choice of the user is probably not taken into account (if you accept really rapidly, before my app register to EasyAPNS then your choice is reflected back on the server at first launch)

Any idea ?

解决方案

There seems to be no way to determine whether the allow pop-up has been shown. I rely on user defaults to keep track of this:

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    BOOL didRegisterForPush = [[NSUserDefaults standardUserDefaults] boolForKey:@"didRegisterForPush"];
    if (!didRegisterForPush) {
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"didRegisterForPush"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
    // .. send deviceToken to server
}

Now you can determine the authorization state using:

- (PushAuthorizationStatus)pushAuthorizationStatus
{
    UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
    if (types) {
        return kPushAuthorizationStatusAuthorized;
    }
    BOOL didRegisterForPush = [[NSUserDefaults standardUserDefaults] boolForKey:@"didRegisterForPush"];
    if (didRegisterForPush) {
        return kPushAuthorizationStatusDenied;
    }
    return kPushAuthorizationStatusNotDetermined;
}

Using this you can send the NotDetermined state to the server instead of Denied.

这篇关于追踪推送通知的用户选择[允许/不要]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆