- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
是否可以从 uiwebview 访问 iPhone 的相机?我知道phonegap是吗,但是如何让它在没有phonegap的情况下工作呢?
谢谢。
最佳答案
您可以实现 UIWebView 委托(delegate)并拦截任何尝试的页面加载。通过设置自定义 url,您可以将消息传递给 Objective C,从而启动相机。要将数据发送回 Web 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
关于iphone - 从 uiwebview 访问相机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2915881/
我正在寻找一种方法来观察 UIWebView 中文本选择已开始或结束的通知。一旦出现大头针和蓝色选择覆盖,它会自动更新 Javascript 选择和范围对象,但是当您点击选择并结束时,似乎没有一种干净
我需要获取 UIWebView 的 url在用户单击一次后显示。 我尝试在 UIWebView 下放置一个按钮,该按钮调用确定 url 的方法。 ,但这样按钮不起作用。我试过在 UIWebView 上
我正在使用 AFNetworking UIWebView 类别,我想知道是否有任何方法可以通过证书固定检查加载 url。 最好的问候, 最佳答案 UIWebView 没有向它公开任何直接 API,但它
我想从应用程序中禁用长触摸。我无法控制在 WebView 上加载的 HTML。 最佳答案 在 webViewDidFinishLoad委托(delegate)我在加载的 html 页面上运行一个禁用长
每个人: 我可以通过将scalesPageToFit 设置为YES 来启用缩放。但是,我如何知道 UIWebView 是否正在缩放? 有人知道吗? 提前致谢。 最佳答案 已解决。 向 XXXViewC
我在每个单元格中都有几个自定义单元格和 WebView 。现在,我的要求是找到要在 webview 上加载的 HTML 字符串的高度,然后根据此更改自定义单元格高度和 webview 高度。 我知道可
我想嵌入一个 UIWebView进入我的 MonoTouch 应用程序,用于尚未本地实现的区域。 为了对网站进行身份验证,我想设置一个包含当前 session key 的 cookie。 我尝试创建一
我的应用程序使用 UIWebview,它在 iOS 5 和 iOS 6 中运行良好。但是,当我在 Xcode 5 中构建并运行相同的代码时,它不会在 iOS 7 中加载网页。 - (void)web
我有一个嵌入式网站,有很多链接,但 WebView 窗口相当小,允许放大和缩小列表上方的较大图像。如果可能的话,我需要 webview 响应到带有第二个嵌入式 UIWebView 的新 Control
我正在 Monotouch 上构建 iPhone 应用程序。我的项目的一部分使用本地网站内容。我将网站使用的所有 html、js、css 和图像复制到一个文件夹中,并将其导入到我的 monotouch
在下面的示例中,infoScroller 是一个UIWebView,println(HTMLDescription) 打印一个可爱的 HTML 字符串。但是,尝试 loadHTMLString 会出现
我有一个包含多个 UIWebView 的应用程序。我有一个 UIWebView 保存所有业务逻辑和其他 UIWebViews 用于显示目的。但是,我发现如果 UIWebView 不是最后一个加载的,断
我的一个包含链接的 View Controller 底部有一个 Web View 。我想要做的是,当用户单击 Web View 中的一个链接时,它会打开一个 Web View ,该 View 占据屏幕
我已经在 webview 中实现了 ScrollView 的委托(delegate)。由于,iOS 5 默认 ScrollView 不再响应 didZoom 事件。为什么会出现这种行为? 最佳答案 i
我正在使用新的 Xcode UI Testing来自 XCTest Framework与 Xcode 7 GM .我有一个带有简单 UIWebView 的应用程序(它只是一个带有 web View 和
我无法从 UIWebView 响应中获取 header ,因为响应显然没有被缓存。有解决方法吗?我试过来自 here 的代码. 我的应用程序使用混合的原生 iOS View Controller 和
我想制作一个简单的应用程序,其中具有自定义内容的 UIWebView 将具有多个指向具有类似内容的其他页面的链接(顶部有一个导航栏,只有一个后退按钮)。我阅读了this的答案问题,但是我不确定是否应该
我制作了一个简单的测试项目,其中仅包含一个 UIWebView,其中 UIView 填充了窗口。当 UIWebView 的宽度与 UIView 相同时,一切正常。当UIWebView的宽度小于容器的宽
在我的 iPad 应用程序中,有一个显示文本内容的 UIWebview。当我按住并选择一个文本时,应该会弹出一个带有 2 个自定义菜单的菜单。 说,|菜单 1 |菜单2 | 但似乎 COPY 菜单也会
是否可以在 uiwebview.js 中加载应用商店链接。我尝试在 uiwebview 中打开它,但它没有加载到那里。我不希望用户在单击我的应用程序中的网址时离开我的应用程序。可能吗? 问候 潘卡杰
我是一名优秀的程序员,十分优秀!