这有点落后于大多数人的要求。我想故意触发询问用户权限的对话框:
- 连接到蓝牙设备,即使在离线时也是如此。
- 在那里访问基于 iOS 的 Twitter 帐户。
我已经有一个类似的位置对话框可以正常工作。我这样做是因为我想让请求许可的过程更温和一些,就像 Heyday 一样,通过显示一个欢迎屏幕来解释为什么应用程序需要这项服务,然后当用户点击 OK、发起请求并触发对话框。
我已经尝试了一些东西。对于 Twitter,我尝试了以下方法:
- (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
});
}];
}
但是,尽管给予了许可,但它是自动的,而不是用户看到一个对话框并批准它的结果。
对于蓝牙版本,我还没有找到一些可以触发它的代码。文档和编程指南在请求权限的问题上都相对安静。我能找到的唯一一个参考是,通过为bluetooth-peripheral
用户设置一个 plist 键,将在应用程序启动时自动提示。这在流程中太早了,没有用。