在我的应用程序中,我有一个上传文件的功能,为此,我给了一个按钮。如果我们点击btn,我们会弹出一个选项,选择“选择照片”或“拍照”。如果我们点击选择照片选项,我会遇到例外情况
支持的方向与应用程序没有共同的方向,并且应该是返回YES 。
这是我给出的代码
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
-(IBAction)SettingBtn:(id)sender forEvent:(UIEvent*)event
{
TSActionSheet *actionSheet = [[TSActionSheet alloc] initWithTitle:@" "];
[actionSheet addButtonWithTitle:@"Take Photo" block:^{
NSLog(@"Take Photo");
[self openCamera];
}];
[actionSheet addButtonWithTitle:@"Choose Photo" block:^{
NSLog(@"Choose Photo");
[self pick];
}];
actionSheet.cornerRadius = 3;
[actionSheet showWithTouch:event];
}
-(void)openCamera
{
//[popOverForPicker dismissPopoverAnimated:YES];
@try
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.navigationBar.tintColor = [UIColor blackColor];
[self.navigationController presentViewController:picker animated:YES completion:nil];
}
@catch (NSException *exception)
{
CustomAlertView *alert = [[CustomAlertView alloc] initWithTitle:@"No Camera"
message:@"Camera is not available "
delegate:self cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
}
}
-(void)pick
{
@try {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.navigationBar.tintColor = [UIColor blackColor];
popOver = [[UIPopoverController alloc] initWithContentViewController:picker];
[popOver presentPopoverFromRect:self.FileAddButton.bounds inView:self.FileAddButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
self.popOver = popOver;
}
@catch (NSException *exception) {
appdelegate.methodNameString=@"pickFile";
appdelegate.NSExceptionString=[NSString stringWithFormat:@"%@",exception.description];
[self exception];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
@try
{
if (picker.sourceType == UIImagePickerControllerSourceTypeCamera)
{
[picker dismissViewControllerAnimated:YES completion:nil];
UIImage *fullImage = (UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage];
UIImage *thumbImage = [fullImage imageByScalingAndCroppingForSize:CGSizeMake(180,180)];
self.detailItem.fullImage = fullImage;
self.detailItem.thumbImage = thumbImage;
NSData *dataObj = UIImagePNGRepresentation(thumbImage);
base64String=[dataObj base64Encoding];
NSDate *currentDateTime = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MMddyyyy_HHmmss"];
NSString *dateInStringFormated = [dateFormatter stringFromDate:currentDateTime];
fileName = [NSString stringWithFormat:@"IMG_%@.png",dateInStringFormated];
[self Uploadfile];
}
else
{
// [picker dismissViewControllerAnimated:YES completion:nil];
[self.popOver dismissPopoverAnimated:true];
UIImage *fullImage = (UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage];
UIImage *thumbImage = [fullImage imageByScalingAndCroppingForSize:CGSizeMake(180,180)];
self.detailItem.fullImage = fullImage;
self.detailItem.thumbImage = thumbImage;
NSData *dataObj = UIImagePNGRepresentation(thumbImage);
base64String=[dataObj base64Encoding];
NSURL *imageURL = [info valueForKey:UIImagePickerControllerReferenceURL];
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation *representation = [myasset defaultRepresentation];
fileName = [representation filename];
NSLog(@"fileName siva : %@",fileName);
[self Uploadfile];
};
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:imageURL
resultBlock:resultblock
failureBlock:nil];
}
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleLightContent];
}
@catch (NSException *exception)
{
appdelegate.methodNameString=@"didFinishPickingMediaWithInfo";
appdelegate.NSExceptionString=[NSString stringWithFormat:@"%@",exception.description];
[self exception];
}
@finally
{
}
}
我也尝试过包含这个......
- (BOOL)shouldAutorotate {
return NO;
}
答案 0 :(得分:0)
尝试设置viewcontroller的界面方向
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger) supportedInterfaceOrientations
{
//Because your app is only landscape, your view controller for the view in your
// popover needs to support only landscape
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}