Mike Purcell
Mike Purcell

Reputation: 19979

ios9 - Xcode 7 - Swift - Keyboard shows correctly in Simulator but not on an actual Device

I'm experiencing an unusual issue where the keyboard correctly responds to input focus actions in the simulator (hardward keyboard disabled), but when I build and test on an actual device, the keyboard doesn't appear.

The app is a simple SFSafariViewController. Do I need to specify keyboard settings in Info.plist or something similar?

----- Update -----

Adding source code:

import UIKit
import SafariServices

class ViewController: UIViewController
{
    private var urlString:String = "https://example.com"

    override func viewDidLoad()
    {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func viewDidAppear(animated: Bool) {

        super.viewDidAppear(animated)

        // This will remove the status (battery, time, etc) bar
        UIApplication.sharedApplication().statusBarHidden = true

        let svc = SFSafariViewController(URL: NSURL(string: self.urlString)!)

        // Kind of a hack, in that we really aren't removing the navbar
        //  Rather we are adjusting the starting point of the vpc object so it appears as the navbar is hidden
        self.presentViewController(svc, animated: true) {

            var frame = svc.view.frame
            let OffsetY: CGFloat = 42

            frame.origin = CGPoint(x: frame.origin.x, y: frame.origin.y - OffsetY)
            frame.size = CGSize(width: frame.width, height: frame.height + OffsetY)
            svc.view.frame = frame
        }
    }

    override func didReceiveMemoryWarning()
    {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

Upvotes: 1

Views: 480

Answers (1)

Mike Purcell
Mike Purcell

Reputation: 19979

Ugh. Being new to ios development I was 100% certain my code was borked, which was causing the keyboard not to appear. So this morning I created a test project and added each line of code from my project to the test project to see which was causing the perceived breakage.

After all the code was added back, I re-compiled the test project again, and it worked. Same exact code as the normal project, wtf? So then I realized there must be some caching anomaly that is causing the issue, and sure enough I found this post on how to clear Xcode cache. After clearing the cache I re-loaded my project, re-compiled, and sure enough, my project worked as expected.

So in short, when in doubt, clear that cache.

Upvotes: 1

Related Questions