syedfa
syedfa

Reputation: 2809

How to do string formatting in Objective-C?

I am trying to post text from my iPhone app to my wall on Facebook. Everything works fine, however, my problem is that I am not sure how to format the text. I would like to show the user the name, address, city, state, and phone number of the restaurant they are viewing on the app. Here is my relevant code:

- (void)postToWall {

FBStreamDialog* dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.userMessagePrompt = @"Enter your message:";
dialog.attachment = [NSString stringWithFormat:@"{\"name\":\"%@ got straight A's!\",\"href\":\"http://www.example.com/\",\"caption\":\"%@ must have gotten real lucky this time!\",\"description\":\"\",\"media\":[{\"type\":\"image\",\"src\":\"http://www.abc.png\",\"href\":\"http://www.example.com/\"}]}",
                     _facebookName, _facebookName];
dialog.actionLinks = @"[{\"text\":\"Download GetHalal!\",\"href\":\"http://www.example.com/\"}]";
[dialog show];

}

I would like to show the user the restaurant information in the dialog.attachment variable, such that the output on the facebook wall looks like this:

restaurant.name restaurant.address restaurant.city, restaurant.state restaurant.phoneNumber

My problem is, the text above appears to be in JSON format. The restaurant object is available in the class, and I'd like to include it in the code above, but I don't know how. Can anyone show me how to do this?

Upvotes: 0

Views: 338

Answers (1)

magma
magma

Reputation: 8520

Use a JSON library:

https://stackoverflow.com/questions/286087/best-json-library-to-use-when-developing-an-iphone-application

Also, check the Facebook sdk for iOS:

http://developers.facebook.com/docs/guides/mobile/#ios

The accepted answer in this StackOverflow post has the code you need, with JSONfragment:

How to post a message with attachment in Facebook?

(note that, in this case, the library used is http://code.google.com/p/json-framework/ )

Upvotes: 2

Related Questions