Implement prompt, confirm, and query for ios.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4525 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
b3a1f17452
commit
0c993c251b
41
src/ios.m
41
src/ios.m
@ -1,6 +1,7 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
#import <WebKit/WKUIDelegate.h>
|
||||||
#import <WebKit/WKWebView.h>
|
#import <WebKit/WKWebView.h>
|
||||||
#import <WebKit/WKWebViewConfiguration.h>
|
#import <WebKit/WKWebViewConfiguration.h>
|
||||||
|
|
||||||
@ -9,19 +10,55 @@
|
|||||||
|
|
||||||
void tf_run_thread_start(const char* zip_path);
|
void tf_run_thread_start(const char* zip_path);
|
||||||
|
|
||||||
@interface ViewController : UIViewController
|
@interface ViewController : UIViewController<WKUIDelegate>
|
||||||
@property(strong, nonatomic) WKWebView* web_view;
|
@property(strong, nonatomic) WKWebView* web_view;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation ViewController
|
@implementation ViewController : UIViewController
|
||||||
- (void)viewDidLoad
|
- (void)viewDidLoad
|
||||||
{
|
{
|
||||||
[super viewDidLoad];
|
[super viewDidLoad];
|
||||||
WKWebViewConfiguration* configuration = [[WKWebViewConfiguration alloc] init];
|
WKWebViewConfiguration* configuration = [[WKWebViewConfiguration alloc] init];
|
||||||
self.web_view = [[WKWebView alloc] initWithFrame:self.view.frame configuration:configuration];
|
self.web_view = [[WKWebView alloc] initWithFrame:self.view.frame configuration:configuration];
|
||||||
|
self.web_view.UIDelegate = self;
|
||||||
[self.web_view loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:12345/"]]];
|
[self.web_view loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:12345/"]]];
|
||||||
[self.view addSubview:self.web_view];
|
[self.view addSubview:self.web_view];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL result))completionHandler
|
||||||
|
{
|
||||||
|
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:message message:nil preferredStyle:UIAlertControllerStyleAlert];
|
||||||
|
[alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { completionHandler(true); }]];
|
||||||
|
[alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { completionHandler(false); }]];
|
||||||
|
[self presentViewController:alertController animated:YES completion:^{}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler
|
||||||
|
{
|
||||||
|
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:message message:nil preferredStyle:UIAlertControllerStyleAlert];
|
||||||
|
[alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { completionHandler(); }]];
|
||||||
|
[self presentViewController:alertController animated:YES completion:^{}];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)defaultText initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSString *))completionHandler
|
||||||
|
{
|
||||||
|
NSString *sender = [NSString stringWithFormat:@"%@", self.web_view.URL.host];
|
||||||
|
|
||||||
|
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:prompt message:sender preferredStyle:UIAlertControllerStyleAlert];
|
||||||
|
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
|
||||||
|
textField.placeholder = defaultText;
|
||||||
|
textField.text = defaultText;
|
||||||
|
}];
|
||||||
|
[alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
|
||||||
|
NSString *input = ((UITextField *)alertController.textFields.firstObject).text;
|
||||||
|
completionHandler(input);
|
||||||
|
}]];
|
||||||
|
[alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
|
||||||
|
completionHandler(nil);
|
||||||
|
}]];
|
||||||
|
[self presentViewController:alertController animated:YES completion:^{}];
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface AppDelegate : UIResponder<UIApplicationDelegate>
|
@interface AppDelegate : UIResponder<UIApplicationDelegate>
|
||||||
|
Loading…
Reference in New Issue
Block a user