Adding an image to Facebook using social framework

I am getting this error when trying to upload the selected photo for the SLComposeViewController:

[CFNumber retain]: message sent to deallocated instance 0xa1c2c00

The project builds without an errors or warnings. Here is the code:

- (IBAction)test:(id)sender {
    if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

        API* api = [API sharedInstance];
        NSURL* imageURL = [api urlForImageWithId:IdPhoto isThumb:NO];        
        NSData *data = [NSData dataWithContentsOfURL:imageURL];
        UIImage *img = [[UIImage alloc] initWithData:data];

        SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

        [controller setInitialText:@"First post from my iPhone app"];
        [controller addURL:[NSURL URLWithString:@"http://www.appcoda.com"]];
        [controller addImage:img];
        [self presentViewController:controller animated:YES completion:Nil];
    }
}

any ideas why? thanks

edit: Here is the viewDidLoad:

-(void)viewDidLoad {

    API* api = [API sharedInstance];
    //load the caption of the selected photo
    [api commandWithParams:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"stream", @"command", IdPhoto,@"IdPhoto",label.text,@"weddingID", nil] onCompletion:^(NSDictionary *json) {
        //show the text in the label
        NSArray* list = [json objectForKey:@"result"];
        NSDictionary* photo = [list objectAtIndex:0];
        lblTitle.text = [photo objectForKey:@"title"];
    }];
    //load the big size photo
    NSURL* imageURL = [api urlForImageWithId:IdPhoto isThumb:NO];
    [photoView setImageWithURL: imageURL];
           NSLog(@"image url :%@",imageURL);

}

Answers


First check your imageURL is getting correct or not, There is no problem in SLComposeViewController with ARC.

or you can try if your photoView is imageview

- (IBAction)test:(id)sender {
    if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

        SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

        [controller setInitialText:@"First post from my iPhone app"];
        [controller addURL:[NSURL URLWithString:@"http://www.appcoda.com"]];
        [controller addImage: photoView.image];
        [self presentViewController:controller animated:YES completion:Nil];
    }
}

Need Your Help

How can I combine the results of two MySQL tables to form a feed?

mysql sql

I'm making a dashboard with an activity feed on the Q&A site I'm making. Users can follow people and be updated when people they're following do something like ask a question, answer a question...

AS3 FLVPLaybackCaptioning Component Displaying Images?

flash actionscript-3 flash-cs3 flvplayback

I am using the FLVPlaybackCaptioning Component to display captions for a video. We've built a player that uses a FLV file hosted locally or streamed from the server to show captions for a video, a ...