Swiftyinsta: falha (SwiftyInsta.GenericError.weakObjectReleased)

Criado em 24 set. 2019  ·  3Comentários  ·  Fonte: TheM4hd1/SwiftyInsta

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)

})

}

    }
help wanted

Comentários muito úteis

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.

Todos 3 comentários

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.

Esta página foi útil?
0 / 5 - 0 avaliações

Questões relacionadas

canaksoy picture canaksoy  ·  6Comentários

sbertix picture sbertix  ·  27Comentários

reefer picture reefer  ·  18Comentários

sbertix picture sbertix  ·  8Comentários

sbertix picture sbertix  ·  3Comentários