Search code examples
ios7social-frameworkslcomposeviewcontroller

Sharing my ios app details on facebook along with a facebook share


I am adding share functionalities on my facebook app.Like When a "saying" is selected there is a button for sharing that "saying" on facebook.And while clicking this button I can only see the shared saying on my facebook page,there isnt any information about my ios app.How can I make everyone knows that this saying is shared through my iOS app? Please help me....


Solution

  • I may be a little late. Hope this helps.

    You have to use the Accounts framework and the Social framework to share with your app name. First make sure you have set up your App on Facebook correctly. Then you can use the Facebook App ID to share your posts through your app.

    Here is a sample code that shows you how to use the Accounts framework with the Social Framework :

        ACAccountType * facebookAccountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
    
        // At first, we only ask for the basic read permission
        NSArray * permissions = @[@"email"];
    
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"275485699289493", ACFacebookAppIdKey, permissions, ACFacebookPermissionsKey, ACFacebookAudienceOnlyMe, ACFacebookAudienceKey, nil];
    
        NSArray *accounts = [self.accountStore accountsWithAccountType:facebookAccountType];
        //it will always be the last object with single sign on
        self.facebookAccount = [accounts lastObject];
    
        [self.accountStore requestAccessToAccountsWithType:facebookAccountType options:dict completion:^(BOOL granted, NSError *error) {
            if (granted && error == nil) {
                /**
                 * The user granted us the basic read permission.
                 * Now we can ask for more permissions
                 **/
                NSArray *readPermissions = @[ @"publish_actions"];
                [dict setObject:readPermissions forKey: ACFacebookPermissionsKey];
    
                [self.accountStore requestAccessToAccountsWithType:facebookAccountType options:dict completion:^(BOOL granted, NSError *error) {
                    if(granted && error == nil) {
    
    
                        NSDictionary *parameters = @{@"message": @"This Should Work Perfectly !! "};
    
                        NSURL *feedURL = [NSURL URLWithString:@"https://graph.facebook.com/me/feed"];
    
                        SLRequest *feedRequest = [SLRequest
                                                  requestForServiceType:SLServiceTypeFacebook
                                                  requestMethod:SLRequestMethodPOST
                                                  URL:feedURL
                                                  parameters:parameters];
    
                        feedRequest.account = self.facebookAccount;
    
                        [feedRequest performRequestWithHandler:^(NSData *responseData, 
                                                                 NSHTTPURLResponse *urlResponse, NSError *error)
                         {
                             // Handle response
                         }];
    
                    } else {
                        NSLog(@"error is: %@",[error description]);
                    }
                }];
            } else {
                NSLog(@"error is: %@",[error description]);
            }
        }];
    }