I am having difficulty with the post function. The result that I am receiving is "failure(SwiftyInsta.GenericError.weakObjectReleased)"
What am I doing wrong? My apologies if this is a simple mistake. I searched through all of the questions on here and this is as far as I got, it compiles but returns that error.
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
is usually called when APIHandler
is not strong referenced.
If your example means something like this:
func someFunction(cache: Authentication.Response) {
let handler = APIHandler()
handler.authenticate(with: .cache(cache)) { _ in
}
}
Once the completion handler is called, asynchronously, your handler
has already been released.
In order for this to work you need to "persist" it somewhere. For instance.
class SomeClass {
let handler = APIHandler()
func someFunction(cache: Authentication.Response) {
handler.authenticate(with: .cache(cache)) { _ in }
}
}
Meaning handler
won't be deallocated until your SomeClass
instance is.
Thank you, its now getting "failure(SwiftyInsta.GenericError.custom("Invalid response. 400"))". This is my viewController, could you please show me my errors in this one or if your have a working function for posting an image that you could just cut and paste to me that would help me tremendously, I have no idea where this is going wrong
import UIKit
import SwiftyInsta
class DeploymentViewController: UIViewController {
let handler = APIHandler()
@IBOutlet weak var sampleImage: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction 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)
}) }
}
I've opened a new issue for your new exception.
I'll look into it as soon as I have some time :muscle: @trentona
Please reference #106 from now on.
Most helpful comment
SwiftyInsta.GenericError.weakObjectReleased
is usually called whenAPIHandler
is not strong referenced.If your example means something like this:
Once the completion handler is called, asynchronously, your
handler
has already been released.In order for this to work you need to "persist" it somewhere. For instance.
Meaning
handler
won't be deallocated until yourSomeClass
instance is.