Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-27359] iOS: Unable to open modal controller in swift module

GitHub Issuen/a
TypeBug
PriorityLow
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 8.1.0
Fix Version/sn/a
ComponentsiOS
Labelsn/a
ReporterBrian GarcĂ­a
AssigneeJan Vennemann
Created2019-08-01T16:13:41.000+0000
Updated2019-08-27T12:34:39.000+0000

Description

Trying to implement Stripe in iOS with swift I'm not able to show a modal view controller. In order to isolate the cause I've implemented the following call with the same result, the controller does not show up.
@available(iOS 9.0, *)
    @objc(openSafari:)
    func openSafari(args: Array<Any>?) -> Void {
        let safariVC = SFSafariViewController(url: NSURL(string: "https://google.es") as! URL)
         safariVC.delegate=self
         TiApp().showModalController(safariVC, animated: true)
       
    }

Comments

  1. Jan Vennemann 2019-08-27

    Hey [~bgarcia], there is a slight error in your code, but unfortunately also a bug that prevents you from easily using the correct code. You are using TiApp() which will create a new TiApp instance. TiApp.app() to access the singleton instance of TiApp that's properly initialized would be the correct way. However, due to the naming of that method Swift won't correctly recognize it as the singleton getter it is and mark it as unavailable. To access it you need to go through the Objective-C route:
       let safariVC = SFSafariViewController(url: NSURL(string: "https://google.es") as! URL)
       let tiApp: TiApp = TiApp.perform(NSSelectorFromString("app"))!.takeUnretainedValue() as! TiApp
       tiApp.showModalController(safariVC, animated: false)
       
    This should do the trick and open the SFSafariViewController. Moving this ticket to TIMOB to address the naming issue and making the singleton properly accessible from Swift.

JSON Source