Swiftyinsta: 失敗(SwiftyInsta.GenericError.weakObjectReleased)

作成日 2019年09月24日  ·  3コメント  ·  ソース: TheM4hd1/SwiftyInsta

ポスト機能に問題があります。 私が受け取っている結果は「failure(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インスタンスが割り当て解除されるまで割り当て解除されません。

ありがとうございます。「failure(SwiftyInsta.GenericError.custom( "Invalidresponse。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 評価

関連する問題

sbertix picture sbertix  ·  8コメント

effecttwins picture effecttwins  ·  16コメント

anonrig picture anonrig  ·  3コメント

reefer picture reefer  ·  18コメント

sbertix picture sbertix  ·  3コメント