7
A
回答
12
您可以實現UIWebView委託並攔截任何嘗試的頁面加載。通過設置自定義網址,您可以將消息傳遞給Objective C,以便啓動相機。要將數據發送回網絡weiw,您可以啓動一個新的加載(如我在示例中所做的那樣),或者在UIWebView上使用另一種方法傳遞一些JavaScript。
這裏是工作的例子,我只是寫:
#import "WebViewCamAppDelegate.h"
#import <UIKit/UIKit.h>
@interface uiwebviewcameraAppDelegate : NSObject <UIApplicationDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIWebViewDelegate> {
UIWindow *window;
UIViewController *viewController;
UIWebView *webView;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@end
@implementation uiwebviewcameraAppDelegate
@synthesize window;
//This is the HTML we initially show in the WebView. Note the url "showcamera:" is one I
//invented with the intent to intercept it to show the camera.
static NSString *htmlString = @"<br><A href=\"showcamera:\">Show Camera</a>";
//Pretty Basic stuff. We set the UIWebView Delegate so we can intercept the call and set up //a ViewController so we can animate the UIImagePicker
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
viewController = [[UIViewController alloc] init];
webView = [[UIWebView alloc] initWithFrame:window.bounds];
[webView loadHTMLString:htmlString baseURL:nil];
webView.delegate = self;
[viewController.view addSubview:webView];
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES;
}
//Note: I check to make sure the camera is available. If it is not (iPod touch or Simulator) I show the photo library instead.
-(void) showCamera {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
else {
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
imagePicker.delegate = self;
[viewController presentModalViewController:imagePicker animated:YES];
}
//Here we intercept any time the webview tries to load a document. When the user hits our "showcamera: url" we go to work.
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if ([[[request URL] scheme] isEqualToString:@"showcamera"]) {
[self showCamera];
return NO;
}
return YES;
}
//After the imagepicker has done it's thing, we pass the data back to the webview to be displayed.
//If we wanted to be fancy here, we could have done this via Javascript so we could dynamically insert an image without reloading the page.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[viewController dismissModalViewControllerAnimated:YES];
UIImage* image = [info objectForKey:UIImagePickerControllerOriginalImage];
NSData *imageData = UIImageJPEGRepresentation (image, 0.5);
[webView loadData:imageData MIMEType:@"image/jpeg" textEncodingName:@"UTF-8" baseURL:nil];
}
- (void)dealloc {
[viewController release];
[webView release];
[window release];
[super dealloc];
}
@end
相關問題
- 1. iphone如何從UIWebView訪問攝像頭?
- 2. 訪問攝像頭
- 3. HTML5:攝像頭訪問
- 4. 訪問攝像頭失敗
- 5. HTML5 - 訪問攝像頭
- 6. IPhone SDK:攝像頭訪問?
- 7. 訪問IP攝像頭流
- 8. 如何從HTML5訪問攝像頭?
- 9. 如何從Webview中訪問攝像頭?
- 10. 從pyside/opencv訪問攝像頭
- 11. 管理攝像頭 - 無法訪問攝像頭
- 12. 作爲網絡攝像頭訪問手機攝像頭C++
- 13. 如何通過打開的cv從IP攝像頭訪問無線攝像頭?
- 14. 在androidemulator上訪問攝像頭
- 15. 無法訪問攝像頭(Javascript)?
- 16. iphone攝像頭訪問移動網頁
- 17. 如何使用SWT訪問攝像頭
- 18. 在線訪問攝像頭實例
- 19. 如何使用JavaScript訪問攝像頭
- 20. 訪問網絡攝像頭使用vb.net
- 21. 訪問攝像頭的Windows Phone 10
- 22. 在Liferay portlet中訪問攝像頭
- 23. 攝像頭訪問Django項目
- 24. Swift Playground iPad攝像頭訪問
- 25. 使用JMF訪問攝像頭?
- 26. 訪問多個攝像頭的JavaScript getusermedia
- 27. 在瀏覽器中訪問攝像頭?
- 28. Opencv無法訪問我的攝像頭
- 29. 使用PHP訪問攝像頭?
- 30. 如何訪問MacBook上的攝像頭?
嗨布拉德,你有沒有做到這一點的應用程序委託或者只是在任何你設置你的網頁流量嗎? – Rob85 2016-01-14 20:26:10