【问题标题】:Are iOS disabled push notifications only "muted"? [closed]iOS禁用推送通知是否仅“静音”? [关闭]
【发布时间】:2013-07-19 07:17:38
【问题描述】:

当我在开发一个要求用户允许推送通知的 iOS 应用程序时,我想到了这个疑问。如果用户回答“是”,则其设备“push id”被发送到我们的网络服务器,并将其存储在数据库表中。 每次我们想向他发送消息时,我们都使用此 id 与苹果服务通信,该服务实际上将其发送到他的设备;如果他决定停止它们,他可以从 iOS 设置页面中选择性地仅为我们的应用禁用通知。

此操作完成后我们没有收到任何信息,因此我们的服务器没有收到任何通知:它会继续向苹果发送消息,认为它们已送达。

我的问题:当用户从设置中禁用某个应用程序的通知时,设备是否会向 Apple 传达一些信息(在这种情况下:我们能否知道它,以节省带宽跳过不想成为的用户? “已推送”),还是 iOS 只是拒绝(隐藏?)用户已接受然后禁用的应用的推送通知?

如果最后一种情况属实,我们可以认为,随着用户在设备的生命周期内安装大量应用程序,电池寿命将会缩短,因为越来越多的推送通知被远程接收并被本地忽略( ...即使旧的应用程序被卸载??)

【问题讨论】:

  • 查看 APNS 文档中的“反馈服务”。
  • Apple 文档说:“因为设备上不存在预期的应用程序”,这并没有涵盖他的问题。在他的问题中,该应用程序仍然存在,只是从“设置”中禁用了推送通知。当从设置中禁用推送通知以及删除应用程序时,没有关于反馈服务是否列出这些令牌的信息。

标签: ios objective-c apple-push-notifications battery


【解决方案1】:

来自苹果的Local and Push Notification Programming Guide

Apple 推送通知服务包括一个反馈服务,用于 为您提供有关失败推送通知的信息。当一个推 无法传递通知,因为预期的应用程序没有 存在于设备上,反馈服务将该设备的令牌添加到 它的清单。在传递之前过期的推送通知是 不被认为是失败的交付并且不影响反馈 服务。通过使用此信息停止发送推送通知 将无法传递,您减少了不必要的消息 开销并提高整体系统性能。

每天查询反馈服务以获取设备令牌列表。采用 验证设备令牌是否未被使用的时间戳 自生成反馈条目后重新注册。对于每个设备 尚未重新注册,停止发送通知。 APNs 监控供应商在检查反馈方面的努力 服务并避免将推送通知发送到不存在的 设备上的应用程序。

【讨论】:

    【解决方案2】:

    你可以有条件地这样做:

    在 AppDelegate.m 中

    #pragma mark PUSH NOTIFICATION
    
    - (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)token
    {
        NSUInteger rntypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
        // Set the defaults to disabled unless we find otherwise...
        NSString *pushBadge = @"disabled";
        NSString *pushAlert = @"disabled";
        NSString *pushSound = @"disabled";
    
        if(rntypes == UIRemoteNotificationTypeBadge)
        {
            pushBadge = @"enabled";
        }
        else if(rntypes == UIRemoteNotificationTypeAlert)
        {
            pushAlert = @"enabled";
        }
        else if(rntypes == UIRemoteNotificationTypeSound)
        {
            pushSound = @"enabled";
        }
        else if(rntypes == ( UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert))
        {
            pushBadge = @"enabled";
            pushAlert = @"enabled";
        }
        else if(rntypes == ( UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound))
        {
            pushBadge = @"enabled";
            pushSound = @"enabled";
        }
        else if(rntypes == ( UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound))
        {
            pushAlert = @"enabled";
            pushSound = @"enabled";
        }
        else if(rntypes == ( UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound))
        {
            pushBadge = @"enabled";
            pushAlert = @"enabled";
            pushSound = @"enabled";
        }
    
        NSLog(@"PUSH SOUND %@",pushBadge);
        NSLog(@"PUSH ALERT %@",pushAlert);
        NSLog(@"PUSH SOUND %@",pushSound);
    
        NSString *deviceToken = [[[[token description]
                                   stringByReplacingOccurrencesOfString:@"<"withString:@""]
                                  stringByReplacingOccurrencesOfString:@">" withString:@""]
                                 stringByReplacingOccurrencesOfString: @" " withString: @""];
    
        NSLog(@"%d bytes", [token length]);
        NSLog(@"device token = %@", deviceToken);
    }
    
    - (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
        NSString *str1 = [NSString stringWithFormat: @"Error: %@", err];
        NSLog(@"%@",str1);
    }
    
    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
    {
        for (id key in userInfo)
        {
            NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]);
        }
    
        NSLog(@"remote notification: %@",[userInfo description]);
        NSDictionary *apsInfo = [userInfo objectForKey:@"aps"];
    
        NSString *alert = [apsInfo objectForKey:@"alert"];
        NSLog(@"Received Push Alert: %@", alert);
    
        NSString *sound = [apsInfo objectForKey:@"sound"];
        NSLog(@"Received Push Sound: %@", sound);
    
        NSString *badge = [apsInfo objectForKey:@"badge"];
        NSLog(@"Received Push Badge: %@", badge);
        application.applicationIconBadgeNumber = [[apsInfo objectForKey:@"badge"] integerValue];
    
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Notification" message:alert delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];
        [alertView release];
    }
    

    并将其放入 didFinishLaunchingWithOptions 中:

     [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
        [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
    

    并且不要将声音与您的通知一起发送!!!

    【讨论】:

    • 抱歉,我不明白代码与问题的关系。
    • 这样做,不要将声音与您的通知一起发送...我认为列表行将是我的答案!
    猜你喜欢
    • 1970-01-01
    • 2011-12-27
    • 1970-01-01
    • 2018-12-05
    • 1970-01-01
    • 2021-05-09
    • 2015-04-17
    • 1970-01-01
    • 2017-02-24
    相关资源
    最近更新 更多