Estou tendo dificuldades com a função de postagem. O resultado que estou recebendo é "falha (SwiftyInsta.GenericError.weakObjectReleased)"
O que estou fazendo de errado? Minhas desculpas se isso for um erro simples. Eu pesquisei todas as perguntas aqui e isso é tudo que eu consegui, ele compila, mas retorna aquele erro.
func uploadImage() {
let img = imageView.image!
let myCaption = "Sample Caption"
guard let key = UserDefaults.standard.string(forKey: "current.account") else { return print("`key` not found.") }
guard let cache = Authentication.Response.persisted(with: key) else { return print("`Authentication.Response` not found.") }
let handler = APIHandler()
handler.authenticate(with: .cache(cache)) { _ in
let img1: Upload.Picture = Upload.Picture(image: img, caption: myCaption, size: CGSize(width: 30,height: 30) )
handler.media.upload(photo: img1, completionHandler: { (result) in
print(result)
})
}
}
SwiftyInsta.GenericError.weakObjectReleased
geralmente é chamado quando APIHandler
não tem forte referência.
Se o seu exemplo significa algo assim:
func someFunction(cache: Authentication.Response) {
let handler = APIHandler()
handler.authenticate(with: .cache(cache)) { _ in
}
}
Depois que o manipulador de conclusão é chamado, de forma assíncrona, seu handler
já foi liberado.
Para que isso funcione, você precisa "persistir" em algum lugar. Por exemplo.
class SomeClass {
let handler = APIHandler()
func someFunction(cache: Authentication.Response) {
handler.authenticate(with: .cache(cache)) { _ in }
}
}
Significa que handler
não será desalocado até que sua instância SomeClass
seja.
Obrigado, agora está recebendo "falha (SwiftyInsta.GenericError.custom (" Resposta inválida. 400 "))". Este é meu viewController, você poderia me mostrar meus erros neste ou se você tem uma função de trabalho para postar uma imagem que você poderia apenas cortar e colar para mim que me ajudaria tremendamente, eu não tenho ideia de onde isso está errado
import UIKit
import SwiftyInsta
class DeploymentViewController: UIViewController {
let handler = APIHandler()
<strong i="6">@IBOutlet</strong> weak var sampleImage: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
}
<strong i="7">@IBAction</strong> func test(_ sender: Any) {
guard let key = UserDefaults.standard.string(forKey: "current.account") else { return
print("`key` not found.") }
guard let cache = Authentication.Response.persisted(with: key) else { return
print("`Authentication.Response` not found.") }
handler.authenticate(with: .cache(cache)) { _ in }
let img1: Upload.Picture = Upload.Picture(image: self.sampleImage.image!, caption:
"sampleText", size: CGSize(width: 1080,height: 1080) )
self.handler.media.upload(photo: img1, completionHandler: { (result) in
print(result)
}) }
}
Abri um novo problema para sua nova exceção.
Vou investigar assim que tiver algum tempo: muscle: @trentona
Por favor, referencie # 106 de agora em diante.
Comentários muito úteis
SwiftyInsta.GenericError.weakObjectReleased
geralmente é chamado quandoAPIHandler
não tem forte referência.Se o seu exemplo significa algo assim:
Depois que o manipulador de conclusão é chamado, de forma assíncrona, seu
handler
já foi liberado.Para que isso funcione, você precisa "persistir" em algum lugar. Por exemplo.
Significa que
handler
não será desalocado até que sua instânciaSomeClass
seja.