- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
if ([url.scheme isEqualToString:@"mycustomscheme"]) {
NSString *urlString = @"http://google.com/";
NSURL *urlString = [NSURL URLWithString:urlString];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[tapView loadRequest:loadObj];
}
}
“ tapView”(一个UIWebView)在“ ViewController.m”中可以正常工作,但是当我在“ AppDelegate.m”中使用它时,它将无法工作。为了使此代码在我的“ AppDelegate.m”文件中运行,我需要做些什么。由于我是网页设计师,而不是程序员,所以请逐步说明。:)
我的代码试图执行的操作是检测到Safari中加载了“ mycustomscheme://”,当然还要启动该应用程序,然后将google.com加载到UIWebView中(以证明其正常工作)。我以某种方式需要连接tapView,以便由AppDelegate.m对其进行操作。
@daemon使用NSNotificaitonCenter
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
if ([url.scheme isEqualToString:@"mycustomscheme"])
{
NSDictionary *aDict=[NSDictionary dictionaryWithObject:@"http://google.com/" forKey:@"urlToLoad"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"LoadRequestFromAppDel" object:Nil userInfo:aDict];
}
}
在您的viewcontroller中添加观察者
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(LoadRequestFromAppDel:) name:@"LoadRequestFromAppDel" object:Nil];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)LoadRequestFromAppDel:(NSNotification*)aNotif
{
NSString *aStrUrl=[[aNotif userInfo] objectForKey:@"urlToLoad"];
NSURL *urlString = [NSURL URLWithString:aStrUrl];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[tapView loadRequest:loadObj];
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句