I am needing to go to a specified ViewController in my app. I can get to the rootViewController just fine when entering scheme:// in Safari as I've edited my Info.plist. I even came across this:
https://stackoverflow.com/a/10925872/1327809
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
MyViewController *controller = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:[NSBundle mainBundle]];
[self.viewController presentModalViewController:controller animated:YES];
[controller release];
return YES;
}
which is exactly what I want to do with just one problem. I'm having to use RubyMotion (which I'm new to) and therefore don't even have a nib file.
def application( application, handleOpenURL:url )
// desired code
end
Thank you for any possible help and let me know if you need more info.
Updated 6/14/12
I found out that the handOpenURL method is deprecated so now I'm using its replacement.
I've included my code because I cannot for the life of me figure out why I'm getting the black screen. I even removed the if/else from controller.rb and just had it run the initial view controller no matter if through Safari or by directly clicking app and if through Safari, it still was black. If this should be in a new question, please let me know and I will start a new question.
Both didFinishLaunchingWithOptions and openURL have to pass through the workFlowController method which then sends us to controller.rb and runs the method viewWillAppear. It is there that having a URL determines which view controller runs.
I think it's something in app_delegate.rb that isn't coded right. I don't know how the new openURL method code should be different other than what I've commented below. Is there a way to see my logs (I use log and puts within the methods in question) in my console when I run rake device? I would need it to still log when I completely exit the app and try to go back in via Safari because according to the Apple Docs, "If an application is launched as a result of another application requesting it to open a URL resource, UIApplication first sends the application a application:didFinishLaunchingWithOptions: message and then it invokes this method." I'd like to see if this happens in my app when the app isn't running but I open it via URL.
Any feedback would be greatly appreciated. Again, I thank you for your help up to this point. I will keep looking as well.
app_delegate.rb
class AppDelegate
...
def application( application, didFinishLaunchingWithOptions: launchOptions )
...
@window.rootViewController = self.workFlowController
...
true
end
def application( application, openURL: url, sourceApplication: sourceApplication, annotation: annotation )
if sourceApplication !=nil
#should I now be using this instead of from_open_url?
end
...
@window.rootViewController = self.WorkFlowController
@window.rootViewController.from_open_url = true
...
true
end
def workFlowController
@_workFlowController ||= begin
wfController = Auth::Controller.alloc.init
wfController.delegate = self
# return wf controller
wfController
end
end
...
end
controller.rb
module Auth
class Controller < BaseController
...
attr_accessor :delegate, :from_open_url
...
def viewWillAppear( animated )
super
# app loads from URL, password reset controller loads first
if (@from_open_url)
self.presentViewController(
self.urlController,
animated: false
)
else
self.presentViewController(
self.otherController,
animated: false
)
end
end
...
end
end