Ios 如何从url加载图像并共享该图像?
我想使用Ios 如何从url加载图像并共享该图像?,ios,objective-c,uiactivityviewcontroller,Ios,Objective C,Uiactivityviewcontroller,我想使用UIActivityViewController共享图像。 这是我的密码 - (IBAction)shareBUttonClick:(id)sender { for(int i=0; i<[self.imagesDataArray count];i++) { [imageView sd_setImageWithURL:[NSURL URLWithString:[self.imagesDataArray objectAtIndex:i]] placeholderI
UIActivityViewController
共享图像。
这是我的密码
- (IBAction)shareBUttonClick:(id)sender
{
for(int i=0; i<[self.imagesDataArray count];i++)
{
[imageView sd_setImageWithURL:[NSURL URLWithString:[self.imagesDataArray objectAtIndex:i]] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
NSArray *postItems=@[imageView];
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:postItems applicationActivities:nil];
//if iPhone
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
[self presentViewController:controller animated:YES completion:nil];
}
//if iPad
else
{
// Change Rect to position Popover
UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:controller];
[popup presentPopoverFromRect:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/4, 0, 0)inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
}
-(iAction)共享按钮单击:(id)发件人
{
对于(inti=0;i,首先需要准备所有URL和预取图像
NSMutableArray * urls = [NSMutableArray arrayWithCapacity:things.count];
for(int i=0; i<[self.imagesDataArray count];i++) {
[urls addObject:[NSURL URLWithString: self.imagesDataArray[i]]];
}
[SDWebImagePrefetcher sharedImagePrefetcher]
NSMutableArray*url=[NSMutableArray-withcapacity:things.count];
对于(inti=0;i,首先需要准备所有URL和预取图像
NSMutableArray * urls = [NSMutableArray arrayWithCapacity:things.count];
for(int i=0; i<[self.imagesDataArray count];i++) {
[urls addObject:[NSURL URLWithString: self.imagesDataArray[i]]];
}
[SDWebImagePrefetcher sharedImagePrefetcher]
NSMutableArray*url=[NSMutableArray-withcapacity:things.count];
对于(int i=0;i您可以使用sdwebimage downloader async,然后调用upload函数:
[[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:imageUrl] options:SDWebImageDownloaderUseNSURLCache progress:nil completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
if (image && finished) {
// now upload
[self sendImageToShare:(UIImage *)image];
}
}];
/*********************/
- (void)sendImageToShare:(UIImage *)yourImage {
if (yourImage) {
NSMutableArray *activityItems= [NSMutableArray arrayWithObjects:yourImage, nil];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:nil];
}
}
您可以使用sdwebimage downloader async,然后调用upload函数:
[[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:imageUrl] options:SDWebImageDownloaderUseNSURLCache progress:nil completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
if (image && finished) {
// now upload
[self sendImageToShare:(UIImage *)image];
}
}];
/*********************/
- (void)sendImageToShare:(UIImage *)yourImage {
if (yourImage) {
NSMutableArray *activityItems= [NSMutableArray arrayWithObjects:yourImage, nil];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:nil];
}
}
您是否检查图像是否已添加或未分配imageView的内存我是ios新手,您告诉我该怎么做?如果我是静态添加的图像,则其工作文件,但我的图像来自url。请尝试此NSArray*positems=@[imageView];
在此处使用NSArray*positems=@[imageView.image];
警告:尝试显示已显示的图像(null)此错误您是否检查图像是否已添加或未分配imageView的内存我是ios新手,您告诉我该怎么办?如果我是静态添加的图像,则它的工作文件,但我的图像来自url。尝试此NSArray*positems=@[imageView]
在此位置使用NSArray*positems=@[imageView.image];
警告:尝试显示已显示的内容(null)此错误代码正常,但我需要,直接将图像放入共享控制器。code正常,但我需要,直接将图像放入共享控制器。