1

I am trying to tweet something via my App. But I get an error if I leave my app to open the Twitter oAuth Process. I can auth my app through Twitter and open my app after this Authorization, but the withCallbackURL isn't called. Hopefully someone can help me

I get this error:

Can't end BackgroundTask: no background task exists with identifier 2 (0x2), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug.

I am using the OAuthSwift Library.

I added this to the AppDelegate class:

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
    guard let url = URLContexts.first?.url else {
        return
    }
    if (url.host == "howDoYouFeel://") {
        OAuthSwift.handle(url: url)
    }

}

And this to my ViewController:

var oauthswift: OAuth1Swift!
var handle: OAuthSwiftRequestHandle!
var newOAuthToken: String!

override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        view.backgroundColor = .white

        oauthswift = OAuth1Swift(
            consumerKey:    "123",
            consumerSecret: "456",
            requestTokenUrl: "https://api.twitter.com/oauth/request_token",
            authorizeUrl:    "https://api.twitter.com/oauth/authorize",
            accessTokenUrl:  "https://api.twitter.com/oauth/access_token"
        )

        // authorize
        handle = oauthswift.authorize(
            withCallbackURL: URL(string: "howDoYouFeel://")!) { result in
                print("result \(result)")
            switch result {
            case .success(let (credential, response, parameters)):
              print("success")
            print(credential.oauthToken)
              print(credential.oauthTokenSecret)
              print(parameters["user_id"])
              // Do your request
            case .failure(let error):
                print("error")
              print(error.localizedDescription)
            }
        }
    }
Torben G
  • 750
  • 2
  • 11
  • 33
  • Seems to be the same problem as: https://stackoverflow.com/questions/59076416/url-opening-swift-app-open-works-called-function-does-not-work – emmics Dec 11 '19 at 12:52

0 Answers0