简体   繁体   English

以编程方式更改iOS上的隐私设置

[英]Programmatically changing privacy settings on iOS

Over the past day I have been trying to finalize a view controller that accesses the contacts in a user's address book. 在过去的一天里,我一直在尝试最终确定一个访问用户地址簿中的联系人的视图控制器。 I have been signing up with various apps and going through their signup flows where they ask you for access to your address book. 我一直在注册各种应用程序,并通过他们的注册流程,他们要求您访问您的地址簿。

There are 2 different ways that these apps handle address book access: 这些应用程序有两种不同的方式处理通讯簿访问:

  1. The app wants access to contacts, so they show a UIAlertView window that says something like this: "We need to access your address book. You can enable this by going to Settings > Privacy > Contacts > Turn on for App Name. 该应用程序需要访问联系人,因此他们会显示一个UIAlertView窗口,其中显示如下内容:“我们需要访问您的地址簿。您可以通过转到”设置“>”隐私“>”联系人“>”启用应用程序名称“来启用此功能。

  2. The app wants access to contacts, so they show a UIAlertView window that says something like this: "We need to access your contacts so we can find your friends" 该应用程序需要访问联系人,因此他们会显示一个UIAlertView窗口,上面写着:“我们需要访问您的联系人才能找到您的朋友”

What's different though about option 2 is that in the UIAlertView window, they actually have 2 buttons for "Don't Allow" and "OK". 关于选项2的不同之处在于,在UIAlertView窗口中,它们实际上有2个“不允许”和“确定”按钮。

I was under the impression that if you actually press "OK" it will allow access to your contacts, and if you press "Don't Allow" it will block the app from accessing your contacts. 我的印象是,如果您实际按下“确定”,它将允许访问您的联系人,如果您按“不允许”,它将阻止该应用访问您的联系人。

However, even if I press "OK" in these apps, it doesn't even change the privacy settings. 但是,即使我在这些应用程序中按“确定”,它甚至不会更改隐私设置。 Pressing "Don't Allow" doesn't change anything either. 按“不允许”也不会改变任何内容。

So, are these apps just choosing to show "OK" and "Don't Allow" for whatever reason, despite the fact that they don't even work or have any functionality at all? 那么,这些应用程序是否只是出于任何原因选择显示“OK”和“Do not Allow”,尽管它们甚至根本不工作或者根本没有任何功能? I assumed that there was a way to programmatically change the privacy settings, and that by pressing the "OK" button a method was being called that actually did something. 我假设有一种方法可以以编程方式更改隐私设置,并且通过按“确定”按钮,正在调用实际执行某些操作的方法。

I am using iOS 7.0.4 on an iPhone 4S and I just recently started developing for iOS so I only have experience with iOS 7. 我在iPhone 4S上使用iOS 7.0.4,我刚刚开始为iOS开发,所以我只有iOS 7的经验。

I just don't understand what's really possible and why I am experiencing the behavior above. 我只是不明白什么是真的可能,为什么我遇到上述行为。

If someone could clear this up for me I would really appreciate it. 如果有人能为我清除这一点,我会非常感激。

The first one does not change any thing because it is an instruction that tells you how to enable the related privacy settings in the settings app. 第一个不会改变任何东西,因为它是一条指令,告诉您如何在设置应用程序中启用相关的隐私设置。 You have to go to the settings app and navigate to the right view and change the privacy setting by yourself 您必须转到设置应用并导航到右侧视图并自行更改隐私设置

It is possible to access users' contacts on iOS devices. 可以在iOS设备上访问用户的联系人。 And you do not have to make up a customized message to tell users why you need the permission. 而且您不必编写自定义消息来告诉用户您需要该权限的原因。 Apple will prompt the user with a system alertView. Apple将使用系统alertView提示用户。 I think the second one was supposed to bring up the system alertView when you pressed "ok". 我认为当你按下“确定”时,第二个应该调出系统alertView。

You have to put the following code before accessing users' contacts. 您必须在访问用户的联系人之前输入以下代码。 Somewhere in applicationDidFinishLaunching should be good. applicationDidFinishLaunching中的某处应该是好的。

ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL);

  if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {
    ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) {
      if (granted) {
          // access has been granted.
      } else {
          // User denied access
      }
    });
  }
  else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) {
    // The user has previously given access
  }
  else {
    // The user has previously denied access

  }

Short answer is that there is no (Apple authorized) way to change the privacy settings programmatically after the user has chosen the address book access option the first time the app is run. 简短的回答是,在用户第一次运行应用程序时选择了地址簿访问选项后,没有(Apple授权)方式以编程方式更改隐私设置。 Since both of the options you outlined sound like they're developer generated, they can really mean and do anything. 由于您概述的两个选项听起来都像是开发人员生成的,因此它们可以真正意味着做任何事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM