My distribution profile does not allow me to access contacts of my iPhone, Do I need to get some special permission from apple? My developer profile works well i.e it can access the contacts of my phone whereas distribution profile denies it. And it is working well in simulator also both in ios 5 simulator as well as iOS 6 simulator.
thanks in advance..
__block BOOL accessGranted = NO;
if (ABAddressBookRequestAccessWithCompletion != NULL) { // we're on iOS 6
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
NSLog(#"Error ref %#",error);
NSLog(#"Access %i",accessGranted);
accessGranted = granted;
dispatch_semaphore_signal(sema);
});
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
dispatch_release(sema);
}
else { // we're on iOS 5 or older
addressBook = ABAddressBookCreate();
accessGranted = YES;
}
if (accessGranted) {
//my code
}
Related
Following code I have implemented to login with Twitter in ios 8. With the help of this code I am able to successfully login after writing username and password in device's Setting's twitter app. But I am not able to fetch user's profile from Twitter. I am only able to fetch email address.(username for twitter). Following is my code.
In .h file I import frameworks like
#import <Accounts/Accounts.h>
#import <Accounts/AccountsDefines.h>
#import <Social/Social.h>
In .m file I write following code
- (IBAction)btnLoginWithTwiitterClicked:(id)sender {
//[AppCommon showProgressHUD:NSLocalizedString(#"ProgressHUD_LoadingData", #"'Loading Data','Laden van Gegevens','Daten werden geladen' -General message")];
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) // check Twitter is configured in Settings or not
{
self.accountStore = [[ACAccountStore alloc] init]; // you have to retain ACAccountStore
ACAccountType *twitterAcc = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[self.accountStore requestAccessToAccountsWithType:twitterAcc options:nil completion:^(BOOL granted, NSError *error)
{
if (granted)
{
NSArray *accountsArray = [self.accountStore accountsWithAccountType:twitterAcc];
//[AppCommon hideProgressHUD];
NSDictionary *twitterAccount = [[self.accountStore accountsWithAccountType:twitterAcc] lastObject];
NSLog(#"Twitter UserName: %#", [twitterAccount valueForKey:#"username"]);
}
else
{
if (error == nil) {
//[AppCommon hideProgressHUD];
NSLog(#"User Has disabled your app from settings...");
}
else
{
//[AppCommon hideProgressHUD];
NSLog(#"Error in Login: %#", error);
}
}
}];
}
else
{
//[AppCommon hideProgressHUD];
NSLog(#"Not Configured in Settings......"); // show user an alert view that Twitter is not configured in settings.
}
}
Frinds further I have no idea how to fetch user's other detail.
Any help would be appriciable
Thanx in advance.
I am using same code
just try to NSLog or Po twitterAccount. You will see whole dictionary
My app was rejected by the apple review team. According to them the reason is
"17.1: Apps cannot transmit data about a user without obtaining the user's prior permission and providing the user with access to
information about how and where the data will be used.Specifically,
your app accesses the Users contacts with out requesting permission
first"
But, I have used **NSContactsUsageDescription** key in my info.plst to specify the reason of using contacts in my app.
What should I have to do additionally for get permission?
In iOS 6 You Need to use Address-book permission request iphone to access it's Device Contact:-
method of implement code like this example:
ABAddressBookRef addressBook;
if ([self isABAddressBookCreateWithOptionsAvailable]) {
CFErrorRef error = nil;
addressBook = ABAddressBookCreateWithOptions(NULL,&error);
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
// callback can occur in background, address book must be accessed on thread it was created on
dispatch_async(dispatch_get_main_queue(), ^{
if (error) {
} else if (!granted) {
} else {
// access granted
[self GetAddressBook];
}
});
});
} else {
// iOS 4/5
[self GetAddressBook];
}
You have to ask user whether your application can access your Address book. This feature is implemented in iOS 6.0 and above.
You Can try this code Snippet:
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
in - viewWillAppear:
// Asking access of AddressBook
// if in iOS 6
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"6.0"))
{
// Request authorization to Address Book
addressBook_ = ABAddressBookCreateWithOptions(NULL, NULL);
if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined)
{
ABAddressBookRequestAccessWithCompletion(addressBook_, ^(bool granted, CFErrorRef error)
{
if (granted == NO)
{
// Show an alert for no contact Access
}
});
}
else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized)
{
// The user has previously given access, good to go
}
else
{
// The user has previously denied access
// Send an alert telling user to change privacy setting in settings app
}
}
else // For iOS <= 5
{
// just get the contacts directly
addressBook_ = ABAddressBookCreate();
}
I am using the following code to ask the permission from addressbook and save it to app's UserDefaults.
if (ABAddressBookRequestAccessWithCompletion != NULL)
{
// we're on iOS 6
ABAddressBookRef addressBookRef = ABAddressBookCreate();
ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) {
accessgranted = granted;
if(accessgranted)
{
[self saveaddressbookpermission:accessgranted];
[NSThread detachNewThreadSelector:#selector(startbgprocess) toTarget:self withObject:nil];
}
});
CFRelease(addressBookRef);
}
else {
// we're on iOS 5 or older
accessgranted = YES;
[self saveaddressbookpermission:accessgranted];
NSLog(#"in iOS 5");
[NSThread detachNewThreadSelector:#selector(startbgprocess) toTarget:self withObject:nil];
}
The issue is when i try to Reset the privacy settings using Setting->General->Reset -> Reset Location & privacy, but if i try to Change the Privacy Settings from Settings->Privacy-> and switch OFF the permissions from there then my app crashes. How can i handle this situation. Please let me know if any other information required as i am not able to find anything regarding this.
Adding contact to a group not working on device but working on simulator in ABAddressbook
Gives no error but contact is not reflected in particular group in contacts
but works fine on Simulator
I am Using this code
if (person) {
ABAddressBookAddRecord(addressBook, person, nil);
ABAddressBookSave(addressBook, &error);
BOOL isADDED = ABGroupAddMember(groupNameRef, person, &error);
NSError *error1 = (__bridge_transfer NSError *)error;
NSLog(#"Reason = %#", error1.localizedFailureReason);
BOOL iSSaved = ABAddressBookSave(addressBook, &error);
}
works fine on Simulator but not on device
It will help you to start by using error-checking correctly. Here is the structure of an error-checked routine:
if (person) {
bool ok;
CFErrorRef err = nil;
ok = ABAddressBookAddRecord(addressBook, person, &err);
if (!ok) {
NSLog(#"%#", err);
return;
}
ok = ABAddressBookSave(addressBook, &err);
if (!ok) {
NSLog(#"%#", err);
return;
}
ok = ABGroupAddMember(groupNameRef, person, &err);
if (!ok) {
NSLog(#"%#", err);
return;
}
ok = ABAddressBookSave(addressBook, &err);
if (!ok) {
NSLog(#"%#", err);
return;
}
}
Notice the pattern here. The function returns a bool. You examine that bool. If it is false, then you examine the error returned by indirection. If you follow this pattern correctly, you will get better information about what is going wrong.
Edit: Make sure you actually have access to the contacts database. I'm assuming you do, but a major difference between the Simulator and the device is that the Simulator grants access automatically, whereas on the device the user must be presented with the access request dialog (call ABAddressBookRequestAccessWithCompletion) or else there won't be access and attempts to work with the contacts database will fail, perhaps silently.
I am asking permission to access my contacts using the code below.
ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL);
if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {
ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) {
}
else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized)
{
}
else
{
}
So far everything is working but however if I delete the app and debug again the app wont ask me the permission again. Prior to if I accepted or declined I can see it in privacy contacts and the name of my app whether its ON or OFF.
I want the app to ask me the permission pop up. what should i do
restart the device and reinstall the app. Anyway to clear some sort of
cache?
You can reset your privacy settings.
Settings > General > Reset > Reset Location & Privacy.