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

查看:150
本文介绍了当用户更改联系人访问权限时,应用在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. 当应用程序在后台运行时,会进入设置并为应用启用联系人访问权限,

  1. Allows Contacts access in the app,
  2. Quits the app,
  3. Goes to Settings->Privacy->Contacts and disables Contacts access for the app,
  4. Runs the app,
  5. While the app is running in background goes to settings and enables Contact access for the app,

应用程序立即在 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天全站免登陆