アマゾンウェブサービスを使用して画像をアップロードしています。GCDブロックから値にアクセスできません。他のクラスの「myString」の値にアクセスするにはどうすればよいですか?
私のコード:
-(void)request:(AmazonServiceRequest *)request didCompleteWithResponse:(AmazonServiceResponse *)response
{
AppDelegate *del = [[UIApplication sharedApplication]delegate];
if(indicatorView!=nil)
{
[indicatorView removeFromSuperview];
indicatorView=nil;
}
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Upload Completed" message:@"The image was successfully uploaded." delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil, nil];
[alert show];
//del.fileName = url;
// Set the content type so that the browser will treat the URL as an image.
/*S3ResponseHeaderOverrides *override = [[S3ResponseHeaderOverrides alloc] init];
override.contentType = @"image/jpeg";
// Request a pre-signed URL to picture that has been uplaoded.
S3GetPreSignedURLRequest *gpsur = [[S3GetPreSignedURLRequest alloc] init];
gpsur.key = @"NameOfThePicture";
//del.fileName = gpsur.key;
gpsur.bucket = @"pic-bucket";
gpsur.expires = [NSDate dateWithTimeIntervalSinceNow:(NSTimeInterval) 3600]; // Added an hour's worth of seconds to the current time.
gpsur.responseHeaderOverrides = override;
// Get the URL
NSError *error;
url = [self.s3 getPreSignedURL:gpsur error:&error];
NSString *myString = [url absoluteString];
NSLog(@"myStringgg====>%@",myString);
del.fileName = myString;
NSLog(@"URL=====>%@",url);*/
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^
{
// Set the content type so that the browser will treat the URL as an image.
S3ResponseHeaderOverrides *override = [[S3ResponseHeaderOverrides alloc] init];
override.contentType = @"image/jpeg";
// Request a pre-signed URL to picture that has been uplaoded.
S3GetPreSignedURLRequest *gpsur = [[S3GetPreSignedURLRequest alloc] init];
gpsur.key = @"NameOfThePicture";
//del.fileName = gpsur.key;
gpsur.bucket = @"pic-bucket";
gpsur.expires = [NSDate dateWithTimeIntervalSinceNow:(NSTimeInterval) 3600]; // Added an hour's worth of seconds to the current time.
gpsur.responseHeaderOverrides = override;
// Get the URL
NSError *error;
NSURL *url = [self.s3 getPreSignedURL:gpsur error:&error];
NSString *myString = [url absoluteString];
//del.fileName = myString;
NSLog(@"URL=====>%@",url);
if(url == nil)
{
if(error != nil)
{
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"Error: %@", error);
//[self showAlertMessage:[error.userInfo objectForKey:@"message"] withTitle:@"Browser Error"];
});
}
}
else
{
dispatch_async(dispatch_get_main_queue(), ^{
//del.fileName = myString;
//NSLog(@"haURL===>%@",del.fileName);
});
del.fileName = myString;
}
//NSLog(@"nameURL====>%@",url);
});
}
ここで、「myString」変数にアクセスして、他のクラスの値にアクセスできるようにします。ありがとう
プロパティ宣言:
@property(nonatomic、strong)NSString * fileName; // appdelegate.h内@property(nonatomic、strong)NSString * File; //GCDと同じコントローラー内
アップデート:
PictureViewController *pic = [[PictureViewController alloc]init];
**NSLog(@"newNameeee====>%@",pic.File);**
AppDelegate *del = [[UIApplication sharedApplication]delegate];
NSLog(@"LocatedAt====>%@",del.locatedAt);
NSLog(@"FileSize====>%d",del.fileSize);
**NSLog(@"FileName====>%@",del.fileName);**