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

查看:255
本文介绍了我想触发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帐户。

我已经有位置工作的罚款类似的对话。
因为我想打,询问是否允许多一点温柔,像鼎盛时期,通过显示欢迎屏幕解释为什么应用程序需要此服务,则当用户点击OK,发起请求并触发对话的过程中,我这样做。

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
    });
  }];
}

不过,尽管此权限的,它是自动的,一个对话框psented用户存在$ P $的不是结果,并批准它。

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

通过蓝牙版本,我还没有找到一些code,将触发它。无论是文档和编程指南都在要求权限的问题相对平静。唯一的一个参考我能找到的是由具有蓝牙外设用户将被自动地提示在应用程序推出的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模式下,如果你的应用程序不会在后台运行。

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.

是不正确的。

有关Twitter的一部分。我没有尝试过使用该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.

  • "[App]" Would Like Access to Twitter Accounts alert is not shown in iOS 6 and the answer
  • Twitter on ios - How is permission granted to do tweets? and the answer

要测试弹出的问题,你应该手动重置结果<大骨节病>设置设置 - > <大骨节病>常规 - > <大骨节病>重置 - > <大骨节病>重置位置和放大器;隐私

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

只是一个小加法:的>最佳实践

Just a small addition: best practices for asking for user permission

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

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