Here is a sample code (Swift 2.0):
import UIKit
import Fabric
import TwitterKit
class TestViewController1: UIViewController {
init() {
super.init(nibName: nil, bundle: nil)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
var firstTime = true
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
if firstTime {
firstTime = false
presentViewController(TestViewController2(), animated: true){}
}
}
}
class TestViewController2: UIViewController {
init() {
super.init(nibName: nil, bundle: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.whiteColor()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
var firstTime = true
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
if firstTime {
firstTime = false
Twitter.sharedInstance().logInWithCompletion { _, _ in () }
}
}
}
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let consumerKey = "xxxx"
let consumerSecret = "xxxx"
Twitter.sharedInstance().startWithConsumerKey(consumerKey, consumerSecret: consumerSecret)
Fabric.with([Twitter.sharedInstance()])
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window?.rootViewController = TestViewController1()
self.window?.makeKeyAndVisible()
return true
}
}
In this case, TestViewController2 will be dismissed unexpectedly.
Thanks,