Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是否仅禁止iOS推送通知;静音“吗;?_Ios_Objective C_Apple Push Notifications_Battery - Fatal编程技术网

是否仅禁止iOS推送通知;静音“吗;?

是否仅禁止iOS推送通知;静音“吗;?,ios,objective-c,apple-push-notifications,battery,Ios,Objective C,Apple Push Notifications,Battery,当我在开发一款要求用户允许推送通知的iOS应用程序时,我想到了这个疑问。如果用户回答“是”,则其设备“推送id”将发送到我们的Web服务器,该服务器将其存储在db表中。 每次我们想给他发送信息时,我们都会使用这个id与苹果服务进行通信,苹果服务会将信息发送到他的设备上;如果他决定停止,他可以从iOS设置页面有选择地禁用我们应用程序的通知 在这个操作完成后,我们没有收到任何信息,所以我们的服务器不会被告知:它会继续向苹果发送消息,认为它们已经发送了 我的问题:当用户从设置中禁用某个应用程序的通知时

当我在开发一款要求用户允许推送通知的iOS应用程序时,我想到了这个疑问。如果用户回答“是”,则其设备“推送id”将发送到我们的Web服务器,该服务器将其存储在db表中。 每次我们想给他发送信息时,我们都会使用这个id与苹果服务进行通信,苹果服务会将信息发送到他的设备上;如果他决定停止,他可以从iOS设置页面有选择地禁用我们应用程序的通知

在这个操作完成后,我们没有收到任何信息,所以我们的服务器不会被告知:它会继续向苹果发送消息,认为它们已经发送了

我的问题:当用户从设置中禁用某个应用程序的通知时(在这种情况下:我们可以知道它吗,以节省不想再被“推送”的跳过带宽的用户),或者doesiOS简单地拒绝(隐藏?),该设备会告诉苹果什么吗用户已接受然后禁用的应用的推送通知


如果最后一种情况是真的,我们可能会认为,随着用户在设备生命周期内安装了大量应用程序,电池寿命将缩短,因为远程用户接收到的推送通知越来越多,并且在本地被忽略(…即使卸载了旧应用程序??)您可以有条件地这样做:

在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];
}
不要把声音和你的通知一起发送

来自苹果:

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

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


看看APNS文档中的“反馈服务”。苹果文档说:“因为设备上不存在预期的应用程序”,这不包括他的问题。在他的问题中,应用程序仍然存在,只是从设置中禁用了推送通知。没有关于从设置中禁用推送通知以及删除应用程序时反馈服务是否列出这些令牌的信息。抱歉,我不了解代码与问题的关系。请这样做,不要将声音与通知一起发送…我认为列表行将是我的anwser!!
 [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
    [UIApplication sharedApplication].applicationIconBadgeNumber = 0;