Invite multiple friends using the Facebook SDK to a native app

I use the FB SDK so that users can invite friends to download my application. I create an FB request when the user clicks the invitation button. The action is as follows:

- (IBAction)inviteButtonPressed:(UIButton *)sender { // create a dictionary for our dialog parameters NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity: 7]; // set the frictionless requests parameter to "1" [params setObject: @"1" forKey:@"frictionless"]; [params setObject: @"Test Invite" forKey:@"title"]; [params setObject:appID forKey:@"app_id"]; [params setObject: @"Test" forKey: @"message"]; if([friendsToInvite count] != 0){ [params setObject:friendsToInvite forKey:@"to"]; NSLog(@"%@", params); } // show the request dialog [facebook dialog:@"apprequests" andParams:params andDelegate: nil]; } 

The problem is that I am passing an array of friends (selected by the user) for the @ "to" property object. So the Facebook library is trying to parse the @ "to" object (code from Facebook):

  id fbid = [params objectForKey:@"to"]; if (fbid != nil) { // if value parses as a json array expression get the list that way SBJsonParser *parser = [[[SBJsonParser alloc] init] autorelease]; id fbids = [parser objectWithString:fbid]; if (![fbids isKindOfClass:[NSArray class]]) { // otherwise seperate by commas (handles the singleton case too) fbids = [fbid componentsSeparatedByString:@","]; } invisible = [self isFrictionlessEnabledForRecipients:fbids]; } 

My code gives me this error:

 -[__NSArrayM UTF8String]: unrecognized selector sent to instance 0x1aea00 2012-05-08 01:48:29.958 shmob[2976:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM UTF8String]: unrecognized selector sent to instance 0x1aea00' 

When I rigidly bind one application identifier to an @ "to" object, it works! Do you know how I can invite a Facebook friend list?

+4
source share
1 answer

Found fix:

I converted the array to a string using componentsjoinedbystring and then set the string as a parameter to the @ "to" property. Like this:

 if([friendsToInvite count] != 0){ NSString * stringOfFriends = [friendsToInvite componentsJoinedByString:@","]; [params setObject:stringOfFriends forKey:@"to"]; NSLog(@"%@", params); } // show the request dialog [facebook dialog:@"apprequests" andParams:params andDelegate: nil]; 

It works like a charm.

+10
source

Source: https://habr.com/ru/post/1411235/


All Articles