gpt4 book ai didi

ios - Twitter SLComposeViewController 经常触发失败

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:08:52 24 4
gpt4 key购买 nike

我在使用 Twitter SLComposeViewController 时遇到了一个奇怪的问题。我现在在 imagePickerController 方法中有一个错误,显示“发送 void 到不兼容类型 void (^)(void) 的参数”

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

这是照片 Action :

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

最后是 tweet 方法:

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

最佳答案

在单独的方法中编写 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;

关于ios - Twitter SLComposeViewController 经常触发失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20673474/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com