作爲一個聲明,我完全不知道,如果蘋果願意接受本作的應用程序商店,但實現這樣的事情是非常簡單的。下面是我在的appDelegate更改的唯一代碼:
#import "AppDelegate.h"
#import "WebViewController.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
WebViewController *webVC = [[WebViewController alloc] initWithURLString:@"http://www.google.com"];
self.window.rootViewController = webVC;
[self.window makeKeyAndVisible];
return YES;
}
然後我子類一個UIViewController有以下的.h和.m文件:
#import <UIKit/UIKit.h>
@interface WebViewController : UIViewController <UIWebViewDelegate> {
NSString *_url;
}
- (id)initWithURLString:(NSString *)URLString;
@end
#import "WebViewController.h"
@interface WebViewController()
@end
@implementation WebViewController
- (id)initWithURLString:(NSString *)URLString {
self = [super init];
_url = URLString;
return self;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.frame];
webView.autoresizingMask = UIViewAutoresizingFlexibleHeight + UIViewAutoresizingFlexibleWidth;
webView.delegate = self;
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:_url]]];
[self.view addSubview:webView];
}
-(void)webViewDidStartLoad:(UIWebView *)webView {
// perhaps show some sort of loading message here
}
-(void)webViewDidFinishLoad:(UIWebView *)webView {
// hide the loading message here
}
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
// also hide the loading message here and present the user with an appropriate error message
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
return YES;
}
@end
這導致了以下內容:
希望有幫助!
對於Android,請參閱[此答案](http://stackoverflow.com/a/2201999) –
對於Android:只需在佈局中使用webview並顯示您的網頁即可。 – chiru
對於iOS用戶決定他/她是否要在跳板上放置網頁。這[鏈接](http://www.interworks.com/blogs/ssiemens/2012/01/23/get-your-web-app)是一個很好的開端。 – Bamsworld