gpt4 book ai didi

ios - 与 UIActivityViewController 共享图像在 iOS 8 中为空白/损坏

转载 作者:可可西里 更新时间:2023-11-01 06:07:05 26 4
gpt4 key购买 nike

看来我只是在 iOS 8 中遇到了这个错误。我正在尝试与 UIActivityViewController 分享一张图片和一些文本给自己进行测试。有时,共享图像会导致本应是共享图像的问号出现,点击它不会在 iMessage 线程中执行任何操作,因为它要么是空白的,要么是损坏的。如果我返回我的应用程序并再次尝试共享,有时图像会完美共享并且不是空白的。

我正在使用的代码(在 iOS 7 中完美运行):

UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:@[[NSString stringWithFormat:@"Sent from http://appstore.com/appname"],[UIImage imageNamed:@"SomeImage"]]applicationActivities:nil];

activityVC.excludedActivityTypes = @[UIActivityTypeAssignToContact, UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeSaveToCameraRoll, UIActivityTypeAddToReadingList, UIActivityTypePostToVimeo, UIActivityTypeAirDrop];

[self presentViewController:activityVC animated:YES completion:NULL];

我想弄清楚为什么有时会发生这种情况,以及如何解决它。我将不胜感激任何帮助。附上问题/错误的屏幕截图:

enter image description here

最佳答案

这是视频文件共享的解决方法。也许您可以对图像进行同样的尝试。

我有视频数据,我首先将其保存到文档目录中的文件中,然后附加该文件。

//write to a file 
[videoData writeToFile:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/image.mov"] atomically:YES];

(IBAction)ShareVideoWihFacebook:(id)sender {
//get the file url NSString* path =[NSHomeDirectory()stringByAppendingPathComponent:@"Documents/image.mov"];

NSURL *videoURL = [NSURL fileURLWithPath:path];

UIActivityViewController * activityVC = [[UIActivityViewController alloc] initWithActivityItems:@[videoURL,@"Created by ..."] applicationActivities:NULL];


[activityVC setExcludedActivityTypes:@[ UIActivityTypeMail,UIActivityTypeAssignToContact, UIActivityTypeCopyToPasteboard, UIActivityTypePrint, UIActivityTypePostToWeibo,UIActivityTypeMessage,UIActivityTypeAirDrop,UIActivityTypeSaveToCameraRoll]];

[activityVC setValue:@"My Video" forKey:@"subject"];

[activityVC setCompletionHandler:^(NSString *activityType, BOOL completed) {
//NSLog(@"completed dialog - activity: %@ - finished flag: %d", activityType, completed);
}];

[self presentViewController:activityVC animated:TRUE completion:nil];
}

关于ios - 与 UIActivityViewController 共享图像在 iOS 8 中为空白/损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26002690/

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