NSString *firstID = @"https://wallpaperbrowse.com/media/images/soap-bubble-1958650_960_720.jpg";
想象一下,当我传递第一个ID时,我的第一个ID是缩略图,它会得到完整的图像并得到原始图像
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"0");
[self GetFullImage:firstID];
NSLog(@"1");
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"2");
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:PAN applicationActivities:nil];
activityViewController.popoverPresentationController.sourceView = self.view;
[self presentViewController:activityViewController animated:YES completion:nil];
NSLog(@"3");
NSLog(@"PAGGGGGG:%@",PAN);
});
});
第一种方法代码:
- (void)GetFullImage:(NSString *)FullPath{
NSString *UserName = [Appdata sharedDataModel].userNameString;
NSString *Password = [Appdata sharedDataModel].passwordString;
NSString *DeviceType = [Appdata device];
NSString *VersionNo = [Appdata buildVersion];
NSMutableDictionary *parameterDict = [[NSMutableDictionary alloc] init];
[parameterDict setObject:UserName forKey:@"UserName"];
[parameterDict setObject:Password forKey:@"Password"];
[parameterDict setObject:DeviceType forKey:@"DeviceType"];
[parameterDict setObject:VersionNo forKey:@"VersionNo"];
[parameterDict setObject:FullPath forKey:@"FullPath"];
[[APIUtility sharedInstance] get_Orig_Full_Image_Disp:parameterDict finishResult:^(id response) {
if(response){
@try {
iconImage=nil;
dispatch_async(dispatch_get_main_queue(), ^{
[SHaREDATA removeAllObjects];
[SHaREDATA addObject:response];
NSLog(@"15975368420:%@",SHaREDATA);
NSString *FullImage = [[[SHaREDATA objectAtIndex:0]valueForKey:@"Path"]objectAtIndex:0];
NSLog(@"ppppppppppp:%@",FullImage);
NSData* data = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString:FullImage]];
iconImage = [UIImage imageWithData:data];
NSLog(@"YYYYYYYYYY:%@",iconImage);
NSString * savePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/whatsAppTmp.jpg"];
[UIImageJPEGRepresentation(iconImage, 1.0) writeToFile:savePath atomically:YES];
PAN =@[iconImage];
});
}
@catch (NSException *exception) {
}
}
}];
}
结果(我得到(:
2018-04-11 10:03:56.105 search[2119:29318] 0
2018-04-11 10:03:56.107 search[2119:29318] 1
2018-04-11 10:03:56.108 search[2119:29318] 2
2018-04-11 10:03:56.206 search[2119:29318] 3
2018-04-11 10:03:56.206 search[2119:29318] PAGGGGGG:(null)
2018-04-11 10:10:47.299 search[2208:32130] returnDictionary = (
{
Caption = "";
Path = "https://wallpaperbrowse.com/media/images/soap-bubble-1958650_960_720.jpg";
ReturnValue = 0;
}
)
2018-04-11 10:10:47.299 search[2208:32130] 15975368420:(
(
{
Caption = "";
Path = "https://wallpaperbrowse.com/media/images/soap-bubble-1958650_960_720.jpg";
ReturnValue = 0;
}
)
)
2018-04-11 10:10:47.300 search[2208:32130]
ppppppppppp:https://wallpaperbrowse.com/media/images/soap-bubble-1958650_960_720.jpg
2018-04-11 10:10:49.187 search[2208:32130] YYYYYYYYYY:<UIImage:0x7c815d70>, {960, 720}
我尝试了很多方法,但所有方法都像我的结果一样执行,我想先执行获得完整的图像而不是执行UIActivityController
请帮助我,我坚持了这么多天。
当我使用dispatch_sync
它块方法时,就在这种方法中。
在我看来,在这种情况下你应该使用块。使用完成块重新制作GetFullImage:
方法,并在完成块中显示UIActivityController
。您可以查看下面的代码
- (void)GetFullImage:(NSString *)FullPath completion:(void(^)(UIImage* image))completion{
NSString *UserName = [Appdata sharedDataModel].userNameString;
NSString *Password = [Appdata sharedDataModel].passwordString;
NSString *DeviceType = [Appdata device];
NSString *VersionNo = [Appdata buildVersion];
NSMutableDictionary *parameterDict = [[NSMutableDictionary alloc] init];
[parameterDict setObject:UserName forKey:@"UserName"];
[parameterDict setObject:Password forKey:@"Password"];
[parameterDict setObject:DeviceType forKey:@"DeviceType"];
[parameterDict setObject:VersionNo forKey:@"VersionNo"];
[parameterDict setObject:FullPath forKey:@"FullPath"];
[[APIUtility sharedInstance] get_Orig_Full_Image_Disp:parameterDict finishResult:^(id response) {
if(response){
@try {
iconImage=nil;
dispatch_async(dispatch_get_main_queue(), ^{
[SHaREDATA removeAllObjects];
[SHaREDATA addObject:response];
NSLog(@"15975368420:%@",SHaREDATA);
NSString *FullImage = [[[SHaREDATA objectAtIndex:0]valueForKey:@"Path"]objectAtIndex:0];
NSLog(@"ppppppppppp:%@",FullImage);
NSData* data = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString:FullImage]];
iconImage = [UIImage imageWithData:data];
NSLog(@"YYYYYYYYYY:%@",iconImage);
NSString * savePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/whatsAppTmp.jpg"];
[UIImageJPEGRepresentation(iconImage, 1.0) writeToFile:savePath atomically:YES];
PAN =@[iconImage];
if (completion) {
completion(iconImage);
}
});
}
@catch (NSException *exception) {
if (completion) {
completion(nil);
}
}
}
}];
}
用法:
[self GetFullImage:firstID completion:^(UIImage *image) {
if (!image) {
return;
}
NSLog(@"2");
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[iconImage] applicationActivities:nil];
activityViewController.popoverPresentationController.sourceView = self.view;
[self presentViewController:activityViewController animated:YES completion:nil];
NSLog(@"3");
NSLog(@"PAGGGGGG:%@",image);
}];