This is somewhat backward to what most people ask. I want to purposely trigger the dialog asking for the users permission to:
- Connect to bluetooth devices, even when offline.
- Access there iOS-based Twitter account.
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.
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.
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.