我正在使用UIImagePickerController
从设备获取图像。我已经实现了以下步骤:
-(void) openGallery {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
[actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
}]];
[actionSheet addAction:[UIAlertAction actionWithTitle:@"Camera" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
// take photo button tapped.
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}]];
[actionSheet addAction:[UIAlertAction actionWithTitle:@"Photo Library" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
// PhotoLibrary
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}]];
[self presentViewController:actionSheet animated:YES completion:nil];
}
#pragma mark- UIImagePicker Delegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
[picker dismissViewControllerAnimated:YES completion:NULL];
[self.view setUserInteractionEnabled:NO];
[self uploadThemeServiceCall: chosenImage];
}
我尝试创建OS_ACTIVITY_MODE以在环境变量中禁用,但它不起作用。我尝试了其他解决方案,但仍然无法正常工作。它工作正常,但现在不是。
A :)确保对象selectedImage不是零。 B :)使用NSData *imageData = UIImageJPEGRepresentation(imageObject , 1)
将chosenImage
转换为NSData
。使用此imageData作为你的NSUrlRequest
身体。
Alse在这里显示函数uploadThemeServiceCall
的代码。