2013-05-14 48 views
0

我會如何去發佈一個文件,而不是Facebook的圖像?這工作得很好:從文件而不是Facebook發佈圖像?

SLComposeViewController *controllerSLC = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; 
[controllerSLC setInitialText:@" iPhone app"]; 
[controllerSLC addURL:[NSURL URLWithString:@"http://www.example.com"]]; 

[controllerSLC addImage:[UIImage imageNamed:@"icon.png"]]; 

但是我想從發送圖像:

self.imageView.image = [self.photo objectForKey:photoPictureKey]; 
+0

你可以得到圖像,UIImage的*圖像= [self.photo objectForKey:photoPictureKey]。 – sathiamoorthy 2013-05-14 09:59:27

+0

self.photo的數據類型是什麼,以及[self.photo objectForKey:photoPictureKey]返回的是什麼? – 2013-05-14 10:11:59

回答

1

試試這個隊友(iOS6的),

發送影像這種方法,

確保你添加了Social.framework和#import <Social/Social.h>

-(void) uploadToFaceBook:(UIImage *) image{ 


    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]){ 

     SLComposeViewController *fbController =[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; 
     SLComposeViewControllerCompletionHandler __block completionHandler= 
     ^(SLComposeViewControllerResult result){ 

      [fbController dismissViewControllerAnimated:YES completion:nil]; 

      switch(result){ 
       case SLComposeViewControllerResultCancelled: 
       default: 
       { 
        NSLog(@"Cancelled....."); 
       } 
        break; 
       case SLComposeViewControllerResultDone: 
       { 
        NSLog(@"Posted...."); 
        UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Sent" message:nil delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles: nil]; 
        [alert show]; 
       } 
        break; 
      }}; 

     [fbController addImage:image]; 
     [fbController setInitialText:@" iPhone App"]; 
     [fbController addURL:[NSURL URLWithString:@"http://www.example.com"]]; 

     [fbController setCompletionHandler:completionHandler]; 
     [self presentViewController:fbController animated:YES completion:nil]; 
    } 
    else{ 
     UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry" 
                  message:@"You can't post on Facebook right now, make sure your device has an internet connection and you have at least one Facebook account setup" 
                  delegate:nil 
                cancelButtonTitle:@"OK" 
                otherButtonTitles:nil]; 
     [alertView show]; 
    } 
} 
1

如果[self.photo objectForKey:photoPictureKey]代碼返回,你可以使用的UIImage類方法的形象是imageWithContentsOfFile的路徑:

UIImage *fbImage = [UIImage imageWithContentsOfFile:[self.photo objectForKey:photoPictureKey]]; 

然後檢查fbImage是它不是零它添加到的實例之前類SLComposeViewController

if(fbImage!=nil){ 
    [controllerSLC addImage: image]; 
}else{ 
    NSLog('image is nil'); 
} 

如果這種 「[self.photo objectForKey:photoPictureKey]」 的代碼返回一個UIImage實例,然後做到這一點:

UIImage *fbImage = [self.photo objectForKey:photoPictureKey]; 
if(fbImage!=nil){ 
    [controllerSLC addImage: fbImage]; 
}else{ 
    NSLog('image is nil'); 
} 

你也可以檢查是否fbImage是空的:

if(fbImage!=nil && !([fbImage isKindOfClass:[NSNull class]])){ 
    [controllerSLC addImage: fbImage]; 

}

相關問題