mardi 28 juin 2016

UIWebView Desktop Website Won't Work


Partly as an exercise for learning a little iOS programming, and partly because I wish I had a WhatsApp client on iPad, I am trying to create an app that I can personally use as a WhatsApp client for my iPad. All it does is load up the web.whatsapp.com desktop site in a UIWebView like so: override func viewDidLoad() { NSUserDefaults.standardUserDefaults().registerDefaults(["UserAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/601.5.17 (KHTML, like Gecko) Version/9.1 Safari/601.5.17"]) super.viewDidLoad() self.webView.frame = self.view.bounds self.webView.scalesPageToFit = true // Do any additional setup after loading the view, typically from a nib. let url = NSURL(string: "https://web.whatsapp.com") let requestObj = NSMutableURLRequest(URL: url!) webView.loadRequest(requestObj) //webView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height); } This works okay. It does in fact load the correct webapp, rather than redirecting to the whatsapp home page as would usually happen when the server detects a mobile device. However, rather than presenting me with the QR Code screen for log in, it presents me with this: Now, if I use WhatsApp Web from Safari on my iPad (and requesting Desktop version), it works perfectly fine. As you can see, I am requesting the Desktop site for my UIWebView by setting the UserAgent. Now, I am wondering why it would not work in the UIWebView, and whether perhaps there is some other header or value that needs to be set in order to convince the App to work within my UIWebView control?

Aucun commentaire:

Enregistrer un commentaire