我正在使用自定义 URL 方案打开我的应用程序,然后获取链接并在方法中运行。但我无法真正运行该方法。
例如,我无法加载 Web 视图或更改标签或文本字段。那么如何加载网页视图和更改标签?
AppDelegate.m
:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
if (!url) { return NO; }
NSString *URLopen= [[url host] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
ViewController *vc = [[ViewController alloc]init];
vc.URLschemeLink = URLopen;
[vc URLscheme];
return YES;
}
ViewController.h
:
@interface ViewController : UIViewController<MFMailComposeViewControllerDelegate> {
NSString *URLschemeLink;
}
-(void)URLscheme;
@end
ViewController.m
:
@implementation ViewController
@synthesize URLschemeLink;
-(void)URLscheme {
//for example:
label.text = @"Hello"; //nothing will happen
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]]; //Nothing will happen
NSLog ("Method Works Perfect"); //will happen
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Title:"
message:[NSString stringWithFormat:@"%@", URLSchemeLink]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
//UIAlertView will work perfectly and show the URLschemeLink from AppDelegate.
}
好的 无论如何如何加载标签/webview?我测试从应用程序委托传递一个名为 runURLscheme (=true) 的布尔值。然后我在 ViewDidLoad 中写道:
if(runURLscheme==true) {
[self URLScheme];
}
但这不起作用,它不会运行 URLscheme 方法。无论如何,我如何加载标签/网络视图?