如何创建安全的PHP Web服务以供iOS应用程序访问
我正在尝试找出如何正确地将iOS应用程序连接到MySQL数据库。我的模型中有以下代码如何创建安全的PHP Web服务以供iOS应用程序访问,ios,swift,Ios,Swift,我正在尝试找出如何正确地将iOS应用程序连接到MySQL数据库。我的模型中有以下代码 import Foundation protocol HomeModelProtocol: class { func itemsDownloaded(items: NSArray) } class HomeModel: NSObject, NSURLSessionDataDelegate { //properties weak var delegate: HomeModelProtocol! let
import Foundation
protocol HomeModelProtocol: class {
func itemsDownloaded(items: NSArray)
}
class HomeModel: NSObject, NSURLSessionDataDelegate {
//properties
weak var delegate: HomeModelProtocol!
let urlPath = "http://hourofswift.com/service.php" //this will be changed to the path where service.php lives
func downloadItems() {
let url: URL = URL(string: urlPath)!
let defaultSession = Foundation.URLSession(configuration: URLSessionConfiguration.default)
let task = defaultSession.dataTask(with: url) { (data, response, error) in
if error != nil {
print("Failed to download data")
}else {
print("Data downloaded")
self.parseJSON(data!)
}
}
task.resume()
}
}
我已经设置了PHP Web服务。该文件位于web服务器上,具有访问数据库的凭据。我感到困惑的是,如果我不想让我的数据库公开,我该怎么办。iOS应用程序正在访问PHP Web服务,不需要来自iOS应用程序的凭据。这意味着任何具有internet连接的人都可以向PHP Web服务发送请求。如果我不想让数据库公开,我该怎么办?需要某种形式的证书如果有人能提供更多信息,我也会对此感兴趣。需要某种形式的证书如果有人能提供更多信息,我也会对此感兴趣。