In iOS 6, the user can login to Facebook via Settings>Facebook. There is a section on that view where the apps for which the user may choose to allow/disallow use of the Facebook account are listed.
I have integrated the FacebookSDK.framework into my app, and a line appears for the app in this list. Only, the name of my app is not listed, and neither is its app icon.
I have done several searches and can't seem to find a way to get the name/icon added to the list. Can anyone point me in the right direction?
You'll need to use the account store methods to request access:
-(void)authenticateFacebook {
if([UIActivityViewController class] ) {
NSArray *faceBookPermissions = @[@"publish_stream"];
////ACFacebookAppVersionKey: @"1.0",
NSDictionary *faceBookOptions = @{
ACFacebookAppIdKey: @"xxxxxxxx",
ACFacebookPermissionsKey:faceBookPermissions,
ACFacebookAudienceKey:ACFacebookAudienceFriends
};
AppDelegate *del = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if(del.accountStore == nil) {
del.accountStore = [[ACAccountStore alloc] init];
}
if(del.facebookAccount == nil) {
ACAccountType *facebookAccountType = [del.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
[del.accountStore requestAccessToAccountsWithType:facebookAccountType
options:faceBookOptions
completion:^(BOOL granted, NSError *error)
{
if (granted) {
NSArray *accounts = [del.accountStore accountsWithAccountType:facebookAccountType];
del.facebookAccount = [accounts lastObject];
NSLog(@"got an account");
[self performSelectorOnMainThread:@selector(gotAnAccount) withObject:self waitUntilDone:NO];
} else {
NSLog(@"No account");
//fail gracefully
[self performSelectorOnMainThread:@selector(noAccount) withObject:self waitUntilDone:NO];
}
}];
}
}
Once that is done you can post to facebook with your app id as follows:
-(void)postToFacebook:(NSDictionary *)parameters {
AppDelegate *del = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSURL *feedURL = [NSURL URLWithString:@"https://graph.facebook.com/me/feed"];
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodPOST
URL:feedURL
parameters:parameters];
request.account = del.facebookAccount;
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *alertText;
if (error) {
alertText = [NSString stringWithFormat:
@"error: domain = %@, code = %d",
error.domain, error.code];
[self performSelectorOnMainThread:@selector(errorWithRequest:) withObject:alertText waitUntilDone:NO];
} else {
alertText = @"Posted action, id: %@";
[self performSelectorOnMainThread:@selector(cancelButtonAction:) withObject:nil waitUntilDone:NO];
}
NSLog(@"%@",alertText);
}];
}
You'll need your app delegate to have the accountStore and account variables and then create the @selector methods used. Note that the completion handlers should run on the main thread if they do anything with the UI or you'll be sat waiting a while for the completion handler UI code to run.