2011-06-16 97 views
0

我有一個爲Android開發的簡單應用程序,它拍攝一張照片,訪問設備的相機。 我想要在iPhone上運行相同的應用程序。對於android,我們編寫訪問清單文件中相機的權限。你如何在iPhone中使用相機?我們需要在哪裏設置它。誰能幫幫我嗎?如何使用phonegap應用程序訪問iPhone的相機

在此先感謝

回答

0

對於iPhone訪問攝像機,你可以使用下面的代碼。

// Camera 

UIImagePickerController *imgPicker = [[UIImagePickerController alloc] init]; 

imgPicker.delegate = self; 

imgPicker.allowsImageEditing = YES; 

imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera; 

//[self presentModalViewController:imgPicker animated:YES]; 

[objParent presentModalViewController:imgPicker animated:YES]; 

[imgPicker release]; 

如果遇到任何困難,請通知我。

下面是相機的代表方法。

代表名稱:UIImagePickerControllerDelegate,UINavigationControllerDelegate

方法:

#pragma mark UIImagePickerController delegate 

-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 

{ 

    // Access the uncropped image from info dictionary 

    UIImage *imgCapturePhoto = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; 

    [imgPhoto setImage:imgCapturePhoto]; 

    [self dismissModalViewControllerAnimated:YES]; 
} 

-(void)imagePickerControllerDidCancel:(UIImagePickerController *) picker 

{ 

    [picker dismissModalViewControllerAnimated:YES]; 

} 

乾杯

+0

對不起,我沒有提到我使用phonegap。如何使用phonegap應用程序使相機使用.. – Hima 2011-06-16 10:57:00

+0

謝謝。但我使用phonegap.I沒有在objective-c中開發單個應用程序,我應該使用此代碼 – Hima 2011-06-16 11:00:45

+0

嗨,您可以在buuton click事件中使用此代碼。而其餘的委託方法是。讓我知道任何疑問。 – 2011-06-16 12:16:53

相關問題