我正在尝试用iOS 12 Swift应用程序帮助我的老板和同事,以帮助我们更好地管理车间的库存。
所有这些都可以利用iOS 12捆绑的条形码/ QR码读取技术。
用于登录库存服务的网页使用普通的http技术,因此iOS(似乎)不会向我提供让我保存/检索密钥链密码的方法。但是,当我通过Mac访问网站时,我可以保存登录信息。我已经验证登录信息已保存在Mac的钥匙串上(通过iCloud与iPhone共享)。
该网页警告密码(在任一平台上)将以未加密的方式发送。
我已经在https://www.appcoda.com/barcode-reader-swift/修改了一些代码。
我没有完整的Apple开发者帐户,所以目前这不是一个生产应用程序。
www.appcoda.com/barcode-reader-swift和我提供的代码之间的主要区别在于“QRSwiftController.swift”文件的func launchApp函数。轻微修改有助于提高可读性和可用性。 Safari视图控制器用于使一个应用程序内部的所有内容更具凝聚力。
func launchApp(decoded_barcode: String) {
if presentedViewController != nil {
return
}
AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))
let result = decoded_barcode.replacingOccurrences( of:"[^0-9]", with: "", options: .regularExpression)
let startOfURL: String = "http://xxx.webname.com/deploy/artikel.php?nummer="
let fullURL = startOfURL + result
let alertPrompt = UIAlertController(title: "Open App", message: "You're going to open \(fullURL)", preferredStyle: .actionSheet)
let confirmAction = UIAlertAction(title: "Confirm", style: UIAlertActionStyle.default, handler: { (action) -> Void in
if let url = URL(string: fullURL){
let safariVC = SFSafariViewController(url: url)
self.present(safariVC, animated: true, completion: nil)
}
})
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: nil)
alertPrompt.addAction(confirmAction)
alertPrompt.addAction(cancelAction)
present(alertPrompt, animated: true, completion: nil)
}
即使我通过iPhone上的普通Safari访问库存管理网站,每次都会提示输入用户名/密码。
登录屏幕https://imgur.com/a/S2EMYcE的Alt URL
有没有办法通过自动点击用户名/密码的文本字段(通过粘贴信息)然后点击“登录”来解决这个问题?
我已经看过Stackoverflow上的解决方案,但它们看起来非常复杂和/或不再适用于Swift 4。
谢谢!
假设通用用户名和密码,例如“user”和“password”。
最后(作为一种解决方法)我刚刚使用Google Chrome(在iOS上)来完成所有的驴工作(它似乎愿意保存此网站的密码以供将来检索)。
if URL(string: fullURL) != nil {
//let safariVC = SFSafariViewController(url: url)
//self.present(safariVC, animated: true, completion: nil)
UIApplication.shared.openURL(NSURL(string: fullURL)! as URL)
}