カスタム URL スキームを使用してアプリを開き、リンクを取得してメソッドで実行しています。しかし、私は本当にメソッドを実行できません。
たとえば、Web ビューをロードしたり、ラベルやテキスト フィールドを変更したりできません。では、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.
}
とにかくラベル/ウェブビューをロードする方法は? app デリゲートから runURLscheme (=true) という名前の bool を渡すことをテストしました。それから私はViewDidLoadに書いた:
if(runURLscheme==true) {
[self URLScheme];
}
ただし、これは機能しません。URLscheme メソッドは実行されません。とにかくラベル/ウェブビューをロードするにはどうすればよいですか?