Swiftyinsta: 失败(SwiftyInsta.GenericError.weakObjectReleased)

创建于 2019-09-24  ·  3评论  ·  资料来源: TheM4hd1/SwiftyInsta

我在使用 post 功能时遇到困难。 我收到的结果是“失败(SwiftyInsta.GenericError.weakObjectReleased)”

我究竟做错了什么? 如果这是一个简单的错误,我深表歉意。 我在这里搜索了所有问题,就我所知,它可以编译但返回该错误。

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

最有用的评论

SwiftyInsta.GenericError.weakObjectReleased通常在APIHandler不是强引用时调用。

如果你的例子是这样的:

func someFunction(cache: Authentication.Response) {
  let handler = APIHandler()
  handler.authenticate(with: .cache(cache)) { _ in
  }
}

一旦完成处理程序被异步调用,您的handler就已经被释放了。
为了使它起作用,您需要在某处“坚持”它。 例如。

class SomeClass {
  let handler = APIHandler()

  func someFunction(cache: Authentication.Response) {
    handler.authenticate(with: .cache(cache)) { _ in }
  }
}

意思是handler不会被释放,直到你的SomeClass实例被释放。

所有3条评论

SwiftyInsta.GenericError.weakObjectReleased通常在APIHandler不是强引用时调用。

如果你的例子是这样的:

func someFunction(cache: Authentication.Response) {
  let handler = APIHandler()
  handler.authenticate(with: .cache(cache)) { _ in
  }
}

一旦完成处理程序被异步调用,您的handler就已经被释放了。
为了使它起作用,您需要在某处“坚持”它。 例如。

class SomeClass {
  let handler = APIHandler()

  func someFunction(cache: Authentication.Response) {
    handler.authenticate(with: .cache(cache)) { _ in }
  }
}

意思是handler不会被释放,直到你的SomeClass实例被释放。

谢谢,它现在收到“失败(SwiftyInsta.GenericError.custom(“无效响应。400”))”。 这是我的 viewController,你能告诉我我在这个错误中的错误,或者如果你有一个工作功能来发布一张你可以剪切并粘贴给我的图像,这将极大地帮助我,我不知道这是哪里出了问题

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)
        })    }


}

我为您的新异常打开了一个新问题。
我一有时间就会研究一下 :muscle: @trentona
从现在开始请参考#106。

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

rmelnik7777 picture rmelnik7777  ·  19评论

reefer picture reefer  ·  18评论

biox86 picture biox86  ·  12评论

effecttwins picture effecttwins  ·  16评论

sbertix picture sbertix  ·  8评论