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. 从JavaFx访问摄像头
- 2. 访问摄像头
- 3. HTML5 - 访问摄像头
- 4. IPhone SDK:摄像头访问?
- 5. 访问摄像头失败
- 6. HTML5:摄像头访问
- 7. 如何从Webview中访问摄像头?
- 8. 从pyside/opencv访问摄像头
- 9. 管理摄像头 - 无法访问摄像头
- 10. 作为网络摄像头访问手机摄像头C++
- 11. 如何通过打开的cv从IP摄像头访问无线摄像头?
- 12. 如何访问MacBook上的摄像头?
- 13. 通过iPhone Web App访问摄像头
- 14. 访问设备摄像头与getUserMedia
- 15. 如何使用JavaScript访问摄像头
- 16. 在浏览器中访问摄像头?
- 17. 无闪存访问摄像头
- 18. 访问网络摄像头使用vb.net
- 19. iphone摄像头访问移动网页
- 20. PWA手机摄像头访问
- 21. 通过浏览器访问摄像头
- 22. 在Liferay portlet中访问摄像头
- 23. 多个按钮的访问摄像头
- 24. Python:没有OpenCV的访问摄像头
- 25. 用iPhone SDK访问摄像头
- 26. 在androidemulator上访问摄像头
- 27. 访问摄像头的Windows Phone 10
- 28. 如何使用SWT访问摄像头
- 29. 使用JMF访问摄像头?
- 30. Angular 2访问硬件摄像头
嗨布拉德,你有没有做到这一点的应用程序委托或者只是在任何你设置你的网页流量吗? – Rob85 2016-01-14 20:26:10