问题描述
当我离线并进入后台应用程序超过30秒时,我在发送消息时遇到问题,直到我再次进入该应用程序时,消息才会发送。
我已在Apple开发者论坛上发布了此问题:https://developer.apple.com/forums/thread/656778
有人告诉我,我需要使用NSUrlSession解决该问题,
我尝试了这段代码,但是没有用
func postAction(_ sender: Any) {
let Url = String(format: "your url")
guard let serviceUrl = URL(string: Url) else { return }
let parameterDictionary = ["username" : "Test","password" : "123456"]
var request = URLRequest(url: serviceUrl)
request.httpMethod = "POST"
request.setValue("Application/json",forHTTPHeaderField: "Content-Type")
guard let httpBody = try? JSONSerialization.data(withJSONObject: parameterDictionary,options: []) else {
return
}
request.httpBody = httpBody
let session = URLSession.shared
session.dataTask(with: request) { (data,response,error) in
if let response = response {
print(response)
}
if let data = data {
do {
let json = try JSONSerialization.jsonObject(with: data,options: [])
print(json)
} catch {
print(error)
}
}
}.resume()
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)