gpt4 book ai didi

ios - 检查是否启用推送或启用位置 ios sdk

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:23:01 24 4
gpt4 key购买 nike

我正在使用以下代码来检测这两个(推送通知和定位服务)

    [postvars setObject:([CLLocationManager locationServicesEnabled])?@"true":@"false" forKey:@"locationServicesEnabled"];

BOOL pushEnabled = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications];
[postvars setObject:(pushEnabled)?@"true":@"false" forKey:@"pushServicesEnabled"];

但问题是,即使我在应用程序中出现提示时点击不允许,我也总是对两者都成立。同样在设置应用程序中,我检查了位置设置为从不,通知副标题显示。这段代码有什么问题?谁能在这方面指导我。

最佳答案

仅仅检查 [CLLocationManager locationServicesEnabled] 是不够的。

if([CLLocationManager locationServicesEnabled] && 
[CLLocationManager authorizationStatus] != kCLAuthorizationStatusDenied)
{
[postvars setObject:@"true" forKey:@"locationServicesEnabled"];

}

通知检查这个很棒的SO answer

BOOL pushEnabled = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications];
[postvars setObject:(pushEnabled)?@"true":@"false" forKey:@"pushServicesEnabled"];

UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (types == UIRemoteNotificationTypeNone)
{
[postvars setObject:@"false" forKey:@"pushServicesEnabled"];
}

关于ios - 检查是否启用推送或启用位置 ios sdk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39202712/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com