我想触发iOS7询问用户使用蓝牙和Twitter帐户的权限 [英] I want to trigger iOS7 to ask users permission to use Bluetooth and Twitter account

查看:26
本文介绍了我想触发iOS7询问用户使用蓝牙和Twitter帐户的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这与大多数人的要求有些落后.我想故意触发对话框询问用户权限:

This is somewhat backward to what most people ask. I want to purposely trigger the dialog asking for the users permission to:

  • 即使在离线状态下也能连接到蓝牙设备.
  • 访问基于 iOS 的 Twitter 帐户.

我已经有一个类似的定位对话框,可以正常工作.我这样做是因为我想让请求许可的过程更温和一些,就像 Heyday,通过显示一个欢迎屏幕来解释为什么应用程序需要这个服务,然后当用户点击确定"时,启动请求并触发对话框.

I already have a similar dialog for location working fine. I'm doing this because I want to make the process of asking permission a bit more gentle, like Heyday, by showing a welcome screen explaining why the app needs this service then when the user taps OK, initiating the request and triggering the dialog.

我已经尝试了一些东西.对于 Twitter,我尝试了以下操作:

I have tried some things already. For Twitter I have tried the following:

- (void)triggerTwitterApprovalWithCompletion:(void (^)(BOOL, NSError *))completion  {
  self.accountStore = [[ACAccountStore alloc] init]; //setup as a property.
  ACAccountType *twitterAccountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
  [self.accountStore requestAccessToAccountsWithType:twitterAccountType  options:nil completion:^(BOOL granted, NSError *error) { //completion handling is on indeterminate queue so I force main queue inside
    dispatch_async(dispatch_get_main_queue(), ^{
      completion(granted, error); //triggers displaying the next screen, working
    });
  }];
}

但是,虽然授予了权限,但它是自动的,而不是向用户显示对话框并批准它的结果.

But although the permission is given, it is automatic and not a result of the user being presented with a dialog and approving it.

对于蓝牙版本,我还没有找到一些可以触发它的代码.文档和编程指南在请求权限的问题上都相对安静.我能找到的唯一一个参考是,通过为 bluetooth-peripheral 设置 plist 键,用户将在应用程序启动时自动收到提示.这在流程中为时过早,没有用处.

With the Bluetooth version I am yet to find some code that would trigger it. Both the docs and programming guides are relatively quiet on the issue of asking for permissions. The only one reference I can find is that by having a plist key for bluetooth-peripheral the user will be prompted automagically on app launch. This is too early in the flow to be useful.

推荐答案

只有外围角色需要用户权限才能运行.中央可以为所欲为.当您希望用户授予权限时,只需实例化 CBPeripheralManager 即可触发对话框.

Only the peripheral role needs user permission to run. The central can do whatever it wants to. Simply instantiate a CBPeripheralManager when you want the user to give permission and it will trigger the dialog.

pmanager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil];

然后您使用 peripheralManagerDidUpdateState: 委托方法来了解用户的决定.如果您的应用不在后台运行,则无需在 plist 中设置 bluetooth-peripheral 后台模式.

Then you use the peripheralManagerDidUpdateState: delegate method to get informed about the user's decision. You needn't set the bluetooth-peripheral backgrounding mode in the plist if your app does not operate in the background.

请记住,该对话框在应用程序的生命周期内只会弹出一次,并且在删除并重新安装应用程序时不会重置设置.

Keep in mind that the dialog will be popped only once during the lifetime of the application and the setting won't be reset when the app is deleted and reinstalled.

另请注意,鉴于这种行为,

Note also that in light of this behavior, the

我能找到的唯一一个参考是通过有一个 plist 键蓝牙外设将在应用程序上自动提示用户启动.

The only one reference I can find is that by having a plist key for bluetooth-peripheral the user will be prompted automagically on app launch.

这不是真的.

对于推特部分.我还没有尝试使用该 API,但发现有几个答案表明授权是自动为您处理的,否则 iOS 只会在第一次询问.

For the twitter part. I haven't tried to use that API yet but found several answers that suggest authorization is either handled automatically for you or iOS will ask only the first time.

要测试弹出问题,您应该在
设置->常规->重置->重置位置&隐私

To test the popup questions you should manually reset the settings in
Settings->General->Reset->Reset Location & Privacy

只是一个小补充:请求用户许可的最佳做法

这篇关于我想触发iOS7询问用户使用蓝牙和Twitter帐户的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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