Reputation: 1480
I am developing an iPhone application that will send sms the logged in user friends'. I am using FacebookConnect for the same. The problem is I am getting the uid of all friends but what is the way to send SMS to these uids(friends UID).
Thanks, UPT
Please have a look on the following code and I am not able to send the message to friends: To get friends UID:
NSDictionary* params = [NSDictionary dictionaryWithObject:fql forKey:@"query"];
// sessionView = session;
[[FBRequest requestWithDelegate:self] call:@"facebook.friends.get" params:params];
in delegate:
-(void)request:(FBRequest*)request didLoad:(id)result
//doing the following code:
if (@"facebook.friends.get" == request.method) {
NSArray* users = result;
myList =[[NSArray alloc] initWithArray: users];
for(NSInteger i=0;i<[users count];i++) {
NSDictionary* user = [users objectAtIndex:i];
NSString* uid = [user objectForKey:@"uid"];
// NSString* fql = [NSString stringWithFormat:
// @"select name from user where uid == %@", uid];
//NSDictionary* params = [NSDictionary dictionaryWithObject:fql forKey:@"query"];
//[[FBRequest requestWithDelegate:self] call:@"facebook.fql.query" params:params];
NSDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys:uid, @"uid", @"checkSMSCanSend", @"callback", nil];
[[FBRequest requestWithDelegate:self] call:@"facebook.sms.canSend" params:params];
}
and for SMS.canSend: if (@"facebook.sms.canSend" == request.method) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"SMS" message:@"User can send SMS successfully." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
But this is not getting called. Please help to SMS friends.
Upvotes: 1
Views: 1665
Reputation: 4344
First you will need to check whether the user can send SMS-s and if you are allowed to:
http://developers.facebook.com/docs/reference/rest/sms.canSend
To ask extended permissions you'll call something like this (http://developers.facebook.com/docs/reference/fql/permissions)
FBPermissionDialog* dialog = [[[FBPermissionDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.permission = @"sms";
[dialog show];
If user has enabled SMS for your application you can send an SMS using
http://developers.facebook.com/docs/reference/rest/sms.send
NSDictionary* params = [NSDictionary dictionaryWithObjects:@"1234", @"uid", @"hellow world", @"message", nil];
[[FBRequest requestWithDelegate:self] call:@"facebook.sms.send" params:params];
For examples how to call Facebook API methods through iPhone go here: http://github.com/facebook/facebook-iphone-sdk/#readme
Editing my post to also answer to additional question poster posted as an answer
Your mistake is here, you are trying to compare strings using == operator.
if (@"facebook.friends.get" == request.method)
this compares the addresses of two strings. To compare if the string contents are equal you should use isEqualToString
method:
if([@"facebook.friends.get" isEqualToString:request.method])
Upvotes: 1