当用户更改联系人访问权限时,应用程序在 iOS 6 中崩溃 [英] App crashed in iOS 6 when user changes Contacts access permissions

查看:21
本文介绍了当用户更改联系人访问权限时,应用程序在 iOS 6 中崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用地址簿的应用程序.在 iOS 6 中运行时,它会在用户执行需要访问地址簿的操作时运行此代码.

I have an app that uses the Address Book. When running in iOS 6 it runs this code when the user does something that requires Address Book access.

if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined)
{
    ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL);

    ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error)
    {
        if (granted)
        {
            showContactChooser();
        }
    });

    CFRelease(addressBookRef);
}
else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized)
{
    showContactChooser();
}
else
{
    showAccessDeniedAlert();
}

这非常有效:我能够读取联系人信息,并且当用户拒绝访问时,应用会做出相应的反应.

This works perfectly: I am able to read the contacts information and when the user denied access, the app reacts accordingly.

但是,如果用户:

  1. 允许在应用中访问联系人,
  2. 退出应用程序,
  3. 转到设置"->隐私"->联系人"并禁用该应用的联系人"访问权限,
  4. 运行应用程序,
  5. 当应用在后台运行时,会转到设置并启用应用的联系人访问权限,

应用立即在 main() 内崩溃,没有异常信息或有意义的堆栈跟踪.我尝试打开所有异常"和 [NSException raise] 断点,但这并没有给我更多信息.

the app immediately crashes inside main() with no exception information or a meaningful stack trace. I tried turning on the "all exceptions" and [NSException raise] breakpoint, but that didn't give me any more information.

即使应用在启动过程中没有运行上述代码,也可以重现崩溃.

The crash can be reproduced even if the app doesn't run the above code during the launch.

这里发生了什么?是否有我应该订阅的回调?

What's happening here? Is there a callback that I should be subscribing to?

推荐答案

我已经在我自己的应用程序中看到了这个.我也看到其他人报告了这一点.我很确定这是故意的行为.操作系统会杀死任何对隐私权限变化做出反应的后台应用程序.对此,苹果似乎采取了大刀阔斧的方法.这不是崩溃(尽管在调试器中运行时可能会出现这种情况).应用程序因各种其他原因被终止.将此添加到原因列表中.这让我们有更多理由在应用完全重启后做好恢复应用状态的工作.

I've seen this in my own app. And I've seen others report this as well. I'm pretty sure this is deliberate behavior. The OS kills any background apps that react to changes in privacy permissions. Apple appears to have taken a sledgehammer approach to this. It's not a crash (though it may appear so when running in the debugger). Apps get terminated for various other reasons. Add this to the list of reasons. This gives us more reason to do a good job restoring app state upon a full restart of our apps.

请注意,此行为适用于所有各种隐私设置,例如联系人、照片、麦克风、日历和相机.

Note that this behavior applies to all of the various privacy settings such as contacts, photos, microphone, calendar, and camera.

这篇关于当用户更改联系人访问权限时,应用程序在 iOS 6 中崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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