【发布时间】:2016-08-31 09:56:36
【问题描述】:
所以我在 UIViewController 中添加了一个 CDVViewController,它呈现了我的 Cordova 应用程序的索引页面。我添加了一个链接(稍后我将尝试将其解释为objective-c 功能。)和一个按钮。当我加载索引时,我可以单击按钮和链接并查看视觉响应。但是,当它由 CDVViewController 呈现时,它不会。我在下面包含了我的控制器和 index.html 代码,但我也无法使用 Cordova-iOS MainViewController 类与内容交互。有人知道我该如何解决这个问题吗?
这些是我试图用来实现这一目标的参考。
https://cordova.apache.org/docs/en/2.2.0/guide/cordova-webview/ios.html
How to invoke Objective C method from Javascript and send back data to Javascript in iOS?
MyViewController.h
#import <UIKit/UIKit.h>
#import <Cordova/CDVViewController.h>
@interface MyViewController : UIViewController{
}
@property (strong, nonatomic) IBOutlet UIView *MyPlaceholderView;
@end
MyViewController.m
#import "MyViewController.h"
@interface MyViewController ()
@end
@implementation MyViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
CDVViewController* viewController = [CDVViewController new];
viewController.view.frame = _MyPlaceholderView.frame;
[self.view addSubview:viewController.view];
}
@end
index.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<link rel="stylesheet" type="text/css" href="css/index.css">
<title>Hello World</title>
</head>
<body>
<a class="MyButton" href="req://LoadNativeContent">Load Native Content</a>
<button id="button" style="width:100%; height:100px;"> Button 1 </button>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</body>
</html>
【问题讨论】:
标签: ios xcode cordova webview viewcontroller