I am developing an app for an existing website.My requirement is like this :User will login into app through WebView. Now I want to get back the response from webview weather login is successful or not.
Any thoughts on this?
I am developing an app for an existing website.My requirement is like this :User will login into app through WebView. Now I want to get back the response from webview weather login is successful or not.
Any thoughts on this?
you can use XWebView
1.download XWebView using CocoaPods
edit your Podfile
platform :ios, '8.1'
use_frameworks!
pod 'XWebView', '~> 0.9.2'
2.pod install
3.modify your ViewController viewDidLoad() method
let webview = WKWebView(frame: view.frame, configuration: WKWebViewConfiguration())
view.addSubview(webview)
webview.loadPlugin(LoginNotify(), namespace: "loginNotify")
let root = NSBundle.mainBundle().resourceURL!
let url = root.URLByAppendingPathComponent("index.html")
webview.loadFileURL(url, allowingReadAccessToURL: root)
4.create LoginNotify class receive login message in LoginNotify group import Foundation import UIKit
class LoginNotify : NSObject {
func show(text: AnyObject?) {
let title = text as? String
dispatch_async(dispatch_get_main_queue()) {
let alert = UIAlertView(title: title, message: nil, delegate: nil, cancelButtonTitle: "OK")
alert.show()
}
}
}
5.create index.html in LoginNotify group
// when login success use loginNofidy.show notify your swift part
loginNotify.show("login success!");
I dont have the complete solution (workaround), but it this might help:
UIWebView has an event handler LoadStarted
Maybe you can try to find out to which page it is navigating to whenever LoadStarted is triggered. And based on that URL, you may be able to decide if the login was successful or not.
Or make the website navigate to a certain page (if the website is your)
I'm not an iOS developer, so I dont know about this- if the UIWebView internally uses the LoadRequest method to navigate, you should override it and then get the URL from NSUrlRequest object