简体   繁体   中英

How to pass NSURL to view controller from delegate

So my application opens a file format. Since the app is running it uses applicationWillEnterForeground to call application:openURL:sourceApplication:annotation:. Once I have my NSURL in my delegate my previous view opens and I have done anything with the NSURL.

My app of course is using a storyboard so I just can't call the XIB like most tutorials have you do. So my question how do I get that file to view controller to open and progress it?

You can create property in your AppDelegate.h file to hold the NSURL:

@property (nonatomic, string) NSURL *myURL;

And in

application:openURL:sourceApplication:annotation:

save the url to new property:

self.myUrl = url;

After that you can access the url from every single view controller in your app. Passing url from delegate is not good solution because when the

application:openURL:sourceApplication:annotation:

is called your view controller can be nil.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM