0

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
Community
  • 1
  • 1
jpgr
  • 278
  • 2
  • 3
  • 13

1 Answers1

2

I don't know your exact app setup, but you should just be able to use MyViewController.alloc.init instead. Here's a full working example. This loads a default image (foo.png), but if the app is opened via the URL, it presents a modal view with a different image (bar.png).

class AppDelegate
  def application(application, didFinishLaunchingWithOptions:launchOptions)
    @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
    @viewController = Foo.alloc.init
    @window.rootViewController = @viewController
    @window.rootViewController.wantsFullScreenLayout = true
    @window.makeKeyAndVisible
    true
  end

  def application(application, openURL:url, sourceApplication:sourceApp, annotation:annotation)
    # Here's where you might parse the url and decide which view controller to use
    controller = Bar.alloc.init
    @viewController.presentModalViewController(controller, animated:true)
    true
  end
end

class Foo < UIViewController
  def viewDidLoad
    self.view = UIImageView.alloc.initWithImage(UIImage.imageNamed('foo.png'))
  end
end

class Bar < UIViewController
  def viewDidLoad
    self.view = UIImageView.alloc.initWithImage(UIImage.imageNamed('bar.png'))
  end
end
Community
  • 1
  • 1
Dylan Markow
  • 123,080
  • 26
  • 284
  • 201
  • I have updated my question. If you could take a look I would greatly appreciate it, otherwise I'll repost as a completely new question. I'm having a dreadful time find RubyMotion-relevant material online. Thanks! – jpgr Jun 18 '12 at 19:00