gpt4 book ai didi

ios - 如何修复此社交媒体 View 共享 (iOS)?

转载 作者:行者123 更新时间:2023-11-29 03:11:22 25 4
gpt4 key购买 nike

我的主页上有一个按钮,单击该按钮会弹出一个 subview ,其中显示一些可在社交媒体上分享的选项。到目前为止,我有以下代码:

- (IBAction)showActivityView:(id)sender {
NSString *shareText = @"The text I am sharing";
//UIImage how can I add an image
NSArray *itemsToShare = @[shareText];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil]; //creating mini view controller that pops up that shows the social options, subclass of view controller
activityVC.excludedActivityTypes = @[UIActivityTypeAirDrop, UIActivityTypeAssignToContact, UIActivityTypeMail, UIActivityTypePostToTencentWeibo, UIActivityTypePrint, UIActivityTypeCopyToPasteboard];
[self presentViewController:activityVC animated:YES completion:nil];
}

此功能如我所愿,但我正在尝试弄清楚如何添加图像(第二行)。我以为它会是 UIImage *shareImage = @"img.png"; 但它似乎没有用。我的另一个问题是:有没有一种方法可以让 UIImage 行工作后,我是否可以设置一段代码,在分享之前截取用户的高分,而不是创建状态更新或带有静态图像的推文?

最佳答案

迟到的答案,但这是我用于类似事情的代码:

 //takes screenshot
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
CGRect rect = [keyWindow bounds];
UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
[keyWindow.layer renderInContext:context];
UIImage *capturedScreen = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

//Share image and text

NSString *text = [NSString stringWithFormat:@"My score"];

UIActivityViewController *controller =
[[UIActivityViewController alloc]
initWithActivityItems:@[text, capturedScreen]
applicationActivities:nil];

controller.excludedActivityTypes = @[
UIActivityTypeAssignToContact,
UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo,
UIActivityTypePostToTencentWeibo,
];

[self presentViewController:controller animated:YES completion:nil];

希望对您有所帮助。

关于ios - 如何修复此社交媒体 View 共享 (iOS)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22213254/

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