我需要“挂钩”Notification对象。我想要每一个
new Notification(title);
登录到控制台标题,但也创建通知。我想保留Notification对象的值(例如,如果在Notification请求权限之前,则保留此权限)
怎么做?
答案 0 :(得分:0)
您可以覆盖默认构造函数:
static func post(image: UIImage, for username: String) {
let imageData = UIImagePNGRepresentation(image)
let base64Image = imageData?.base64EncodedString(options: .lineLength64Characters)
let url = "https://api.imgur.com/3/upload"
let parameters = [
"image": base64Image
]
Alamofire.upload(multipartFormData: { multipartFormData in
if let imageData = UIImageJPEGRepresentation(image, 1) {
multipartFormData.append(imageData, withName: username, fileName: "\(username).png", mimeType: "image/png")
}
for (key, value) in parameters {
multipartFormData.append((value?.data(using: .utf8))!, withName: key)
}}, to: url, method: .post, headers: ["Authorization": "Client-ID " + Constants.IMGUR_CLIENT_ID],
encodingCompletion: { encodingResult in
switch encodingResult {
case .success(let upload, _, _):
upload.response { response in
//This is what you have been missing
let json = try? JSONSerialization.jsonObject(with: response.data!, options: .allowFragments) as! [String:Any]
print(json)
let imageDic = json?["data"] as? [String:Any]
print(imageDic?["link"])
}
case .failure(let encodingError):
print("error:\(encodingError)")
}
})
}