FBStreamDialog doesn't show attachment - iphone

I use the simple FBStreamDialog example in my iPad app:
FBStreamDialog* pDialog = [[[FBStreamDialog alloc] init] autorelease];
pDialog.delegate = self;
pDialog.userMessagePrompt = #"Example prompt";
pDialog.attachment = #"{\"name\":\"Facebook Connect for iPhone\",\"href\":\"http://developers.facebook.com/connect.php?tab=iphone\",\"caption\":\"Caption\",\"description\":\"Description\",\"media\":[{\"type\":\"image\",\"src\":\"http://img40.yfrog.com/img40/5914/iphoneconnectbtn.jpg\",\"href\":\"http://developers.facebook.com/connect.php?tab=iphone/\"}],\"properties\":{\"another link\":{\"text\":\"Facebook home page\",\"href\":\"http://www.facebook.com\"}}}";
NSLog(#"prompt: %#", pDialog.userMessagePrompt);
NSLog(#"attachment: %#", pDialog.attachment);
[pDialog show];
NSLogs are OK.
The problem is that neither message prompt nor attachment are shown in FBStreamDialog.
Can anyone help?

The problem was in simulator. It works on device.

Related

Photo Posting in Twitter in iOS5

I am new one to twitter integration in iOS5.
I need to post photos in twitter coming from services.
I have searched many and also practiced sample tutorials on this.
I am getting only photo URL. I need to post photo.
Can anyone help me regarding this?
Thanks in advance.
First you need to save the images and then you can post saved image to twitter
self.shareImg.image = [UIImage imageNamed:#"Your Saved image"];
if ([[[UIDevice currentDevice] systemVersion] floatValue] > 5.0) {
// Create the view controller
TWTweetComposeViewController *twitter = [[TWTweetComposeViewController alloc] init];
NSString *str = [NSString stringWithFormat:#"I created this photo http://%#", iTune];
// Optional: set an image, url and initial text
[twitter addImage:self.shareImg.image];
[twitter setInitialText:[NSString stringWithFormat:#"I created this photo using USC Project Trojan App:http://uslofphoto.com. Download http://%#", iTune]];
// Show the controller
[self presentModalViewController:twitter animated:YES];
// Called when the tweet dialog has been closed
twitter.completionHandler = ^(TWTweetComposeViewControllerResult result)
{
NSString *title = #"Tweet Status";
NSString *msg;
if (result == TWTweetComposeViewControllerResultCancelled)
msg = #"Tweet compostion was canceled.";
else if (result == TWTweetComposeViewControllerResultDone)
msg = #"Tweet composition completed.";
// Show alert to see how things went...
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:#"Okay" otherButtonTitles:nil];
[alertView show];
// Dismiss the controller
[self dismissModalViewControllerAnimated:YES];
};
}

subscriberCellularProviderDidUpdateNotifier doesn't work

I wrote a Hello World app, and put the following code in ...ViewController.m:
- (void)viewDidLoad {
[super viewDidLoad];
CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init];
networkInfo.subscriberCellularProviderDidUpdateNotifier = ^(CTCarrier *carrier) {
[[[UIAlertView alloc] initWithTitle:#"SIM Alert"
message:#"This is an alert."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil] show];
};
}
Then I unplugged the SIM card but no alert was shown as expected. Could someone kindly tell me what's wrong? Thanks.
This is the ultimate solution to your question.
CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [networkInfo subscriberCellularProvider];
NSString *mobileNetworkCode = [carrier mobileNetworkCode];
[networkInfo release];
NSLog(#"Mobile Network Code : %#", mobileNetworkCode);
Depending on the mobileNetwork code you can determine whether SIM is present or not on the Device.
If you have a look at apples documentation of CTCarrier some properties, for example carrierName, have a short notice like this:
If you configure a device for a carrier and then remove the SIM card, this property retains the name of the carrier.
So I would guess the same happens for the rest of the API, since the SIM card isn't replaced by a new one the updateNotifier isn't called.

Attaching plain text file using MFMailComposer in iPhone SDK

I've been trying to use MFMailComposer to send a text file with encrypted data within. The problem is my attachment never shows up when when the email arrives in the inbox. Instead, a line of "<br/><br/>" is always present. I'm assuming is has something to do with the mime type and the receivers mail server not know how to read the data but I just can't figure out a solution.
Anyone come across this before and have a solution?
if([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
mailController.mailComposeDelegate =self;
[mailController setSubject:#"Records"];
[mailController setMessageBody:#"" isHTML:YES];
[mailController addAttachmentData:dataToBeEncrypted mimeType:#"text/plain" fileName:#"Records.txt"];
[self presentModalViewController:mailController animated:YES];
[mailController release];
} else {
//Pop up a notification
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Could not send email. Verify Internet conneciton and try again." delegate:nil cancelButtonTitle:#"Done" otherButtonTitles:nil];
[alert show];
[alert release];
}
Thanks for any help you can give!
Think I got a fix. I just took a shot in the dark after seeing another example and it seemed to work. For mimetype, I just put #"mime".
I'm a little weary of it, so I'll have to do some more testing to make sure the file always comes out correct.

Post message on facebook wall from iPhone

I want to post some message on Facebook wall.
I am able to log in and connect with Facebook from iPhone. But I have hard luck to finding out the solution.
Can you please tell me how I can achieve this functionality?
Assuming that you have a valid FBSession Object:
FBStreamDialog* dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.delegate = self; dialog.userMessagePrompt = #"Example prompt";
dialog.attachment = #"{\"name\":\"Facebook Connect for iPhone\"," "\"href
\":\"http://developers.facebook.com/connect.php?tab=iphone\"," "\"caption\":\"Caption
\",\"description\":\"Description\"," "\"media\":[{\"type\":\"image\"," "\"src
\":\"http://img40.yfrog.com/img40/5914/iphoneconnectbtn.jpg\"," "\"href
\":\"http://developers.facebook.com/connect.php?tab=iphone/\"}]," "\"properties \":{\"another link\":{\"text\":\"Facebook home page\",\"href\":\"http://www.facebook.com\"}}}"; // replace this with a friend's UID // dialog.targetId = #"999999";
[dialog show];
Source: Facebook Connect Reference

connect Iphone with Facebook API

I want to connect facebook API's with my IPhone. For this I have downloaded the FBConnect sdk and included the FBConnect group of FBConnect.xcodeproj in my application and then I have written the following code in FacebookAPPViewController.m
- (void)viewDidLoad{
[super viewDidLoad];
session = [FBSession sessionForApplication:#"a31c3e53bba4a5f2b3955d6e5e 876717" secret:#"6ecbefa3807406bd13187297e58efae9" delegate:self];
FBLoginButton *button = [[[FBLoginButton alloc] init] autorelease];
[self.view addSubview:button];
FBLoginDialog* dialog = [[[FBLoginDialog alloc] init] autorelease];
[dialog show];
}
but it is showing error that session undeclared. That is right also because I have not initialized it but if I declare it with class `FBSession then also It displays some error and if I exclude this line then the button to connect to facebook does not appear.
Can some one help me?
Thanks in advance
Gaurav
After setting up the session, you should pass it to the login dialog:
FBSession *session = [FBSession
sessionForApplication:#"a31c3e53bba4a5f2b3955d6e5e 876717"
secret:#"6ecbefa3807406bd13187297e58efae9" delegate:self];
FBLoginDialog* dialog = [[[FBLoginDialog alloc] initWithSession:session] autorelease];
[dialog show];
In your example, you're opening the login dialog right away, so there's no need to add a login button to your view.
PS. I hope you didn't use your real secret key in your code sample...