Johnny Gamez
Johnny Gamez

Reputation: 259

How do I properly handle custom file types in my iPad/iPhone app?

Just some background on the problem:

I've recently registered a certain file type to be opened with my app. It works the very first time (if the app isn't running in the background) then it holds on to the old file when I try to open another one. Is there a convention I should be following? I don't really care what happens to the previous file, I just want the new one to open.

Below is how I pass the NSURL to my root view controller. My root view controller only uses the url property I created in the ViewDidLoad method.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    ViewController *vc = (ViewController *)self.window.rootViewController;
    vc.url = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];
    return YES;
}

Upvotes: 0

Views: 46

Answers (1)

Johnny Gamez
Johnny Gamez

Reputation: 259

I figured it out.

All I had to do was implement -(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url in my AppDelegate.

I made a helper function in my ViewController named loadFileWithUrl:(NSURL *)filePath and handled the new NSURL in there.

Here is the code from my AppDelegate:

-(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    ViewController *vc = (ViewController *)self.window.rootViewController;
    [vc loadFileWithUrl:url];

    return YES;
}

Upvotes: 1

Related Questions