2013-08-05 24 views
1

添加到Facebook的圖片我越來越想上傳的SLComposeViewController選定的照片時,此錯誤:利用社會框架

[CFNumber挽留]:發送到釋放實例消息0xa1c2c00

該項目建立無錯誤或警告。 這裏是代碼:

- (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]; 
    } 
} 

任何想法爲什麼?感謝

編輯: 這裏是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); 

} 
+0

? –

+0

耶正在使用ARC – user2636326

+0

您是否在調試器中發現錯誤? –

回答

2

首先檢查你的imageURL越來越正確與否, 有一個在SLComposeViewController與ARC沒有問題。

,或者你可以嘗試,如果你的PhotoView中是否使用ARC的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]; 
    } 
} 
+0

你介意解釋我將如何檢查? – user2636326

+0

將其打印在NSLog中(@「image url:%@」,imageURL)' –

+0

NSLog顯示imageURL獲取正確的路徑,但只在viewDidLoad中(請參閱編輯原始文章)。當啓動IBAction測試時,調試器在不顯示NSLog的情況下顯示相同的錯誤。 – user2636326