Twitter SLComposeViewController经常无法触发

时间:2013-12-19 04:27:19

标签: ios iphone objective-c twitter

我对Twitter SLComposeViewController有一个奇怪的问题。我现在在imagePickerController方法中有一个错误,说“将void发送到不兼容类型的参数void(^)(void)”

我也收到一条警告,其中包含推特图片“从imagepicker中选择的图像”我如何从图像选择器中实际获取图像?谢谢!

以下是照片操作:

-(void) photoAction {
        UIImagePickerController *imagePickerController = [[UIImagePickerController alloc]
                                                          init];
    #if TARGET_IPHONE_SIMULATOR
        imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    #else
        imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
    #endif
        imagePickerController.editing = YES;
        imagePickerController.delegate = (id)self;
        [self presentViewController:imagePickerController animated:YES completion:nil];
    }

以下是下一个方法:

-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    [[picker presentingViewController] dismissViewControllerAnimated:YES completion:[self showTweetSheet]];
     }

最后是推文方法:

-(void)showTweetSheet
{
    SLComposeViewController *tweetSheet = [SLComposeViewController
                                           composeViewControllerForServiceType:
                                           SLServiceTypeTwitter];

    tweetSheet.completionHandler = ^(SLComposeViewControllerResult result) {
        switch(result) {
            case SLComposeViewControllerResultCancelled:
                break;
            case SLComposeViewControllerResultDone:
                break;
        }
    };

    [tweetSheet setInitialText:@"Text"];

     if (![tweetSheet addImage:@"image selected from imagepicker"]) {
         NSLog(@"Unable to add the image!");
     }

     if (![tweetSheet addURL:[NSURL URLWithString:@"http://twitter.com/"]]){
         NSLog(@"Unable to add the URL!");
     }

     [self presentViewController:tweetSheet animated:NO completion:^{
        NSLog(@"Tweet sheet has been presented.");
    }];
     }

1 个答案:

答案 0 :(得分:2)

以单独的方法

编写SlcomposeViewController代码
-(void)showTweetSheet
 {
      SLComposeViewController *tweetSheet = 
       [SLComposeViewController composeViewControllerForServiceType: SLServiceTypeTwitter];

      tweetSheet.completionHandler = ^(SLComposeViewControllerResult result) {
          switch(result) {
             case SLComposeViewControllerResultCancelled:
                  break;
             case SLComposeViewControllerResultDone:
                  break;
          }
      };

     [tweetSheet setInitialText:@"Text];

     if (![tweetSheet addImage:image]) {
         NSLog(@"Unable to add the image!");
     }       

     if (![tweetSheet addURL:[NSURL URLWithString:@"http://twitter.com/"]]){
         NSLog(@"Unable to add the URL!");
     }

     [self presentViewController:tweetSheet animated:NO completion:^{
         NSLog(@"Tweet sheet has been presented.");
      }]; 
}

当解雇imagePickerController

[[picker presentingViewController] dismissViewControllerAnimated:YES completion:^{
    [self showTweetSheet]
}];

还在.h文件中声明您的图像实例

UIImage *image;