私のCordovaアプリケーションのインデックスページをレンダリングするUIViewControllerにCDVViewControllerを追加しました。私はリンクを追加しました(これは後でobjective-cの機能として解釈しようとしています)とボタンです。インデックスを読み込むと、ボタンとリンクをクリックして視覚的な反応を見ることができます。しかし、それがCDVViewControllerによってレンダリングされているときは、それはしません。下記のコントローラとindex.htmlコードを追加しましたが、Cordova-iOSのMainViewControllerクラスを使用してコンテンツとやり取りすることもできません。誰も私がこれをどのように修正できるか知っていますか?iOS - CordovaのWebviewコンテンツと対話できません
これは私がこれを達成するために使用しようとしていた参考資料でした。
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>