[GH-ISSUE #445] Objective C Example #291

Closed
opened 2026-03-03 16:47:25 +03:00 by kerem · 3 comments
Owner

Originally created by @lewis-smith on GitHub (Mar 15, 2018).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/445

Description:

I have a project which is mostly Objective C, but I am trying to do new work in Swift where possible.

I am adding an integration with Fitbit.

I have created a class in Swift to handle all the business logic, but I am looking to deal with the URL handler in AppDelegate which is an Objective C file.

I am not able to get the correct syntax for this.

The code (and this template!) implies support for Objective C, but a worked example for this would be hugely appreciated

Tried:

@import OAuthSwift;

 // ...

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {

    if ([url.host isEqualToString: @"oauth-callback"]) {
        [OAuthSwift handleUrl:url];
        return true;
    }
}

Gets compile error:

No known class method for selector handleUrl

OAuth Provider (Twitter, Github, ..):

Fitbit

OAuth Version:

  • Version 1
  • Version 2

OS (Please fill the version) :

  • iOS :
  • OSX :
  • TVOS :
  • WatchOS :

Installation method:

  • Carthage
  • CocoaPods
  • Manually

Library version:

  • head
  • v1.2 (Swift 4.0)
  • v1.0.0
  • v0.6
  • other: (Please fill in the version you are using.)

Xcode version:

  • 9.0 (Swift 4.0)

  • 9.0 (Swift 3.2)

  • 8.x (Swift 3.x)

  • 8.0 (Swift 2.3)

  • 7.3.1

  • other: (Please fill in the version you are using.)

  • objective c

Originally created by @lewis-smith on GitHub (Mar 15, 2018). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/445 ### Description: I have a project which is mostly Objective C, but I am trying to do new work in Swift where possible. I am adding an integration with Fitbit. I have created a class in Swift to handle all the business logic, but I am looking to deal with the URL handler in `AppDelegate` which is an Objective C file. I am not able to get the correct syntax for this. The code (and this template!) implies support for Objective C, but a worked example for this would be hugely appreciated Tried: @import OAuthSwift; // ... - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { if ([url.host isEqualToString: @"oauth-callback"]) { [OAuthSwift handleUrl:url]; return true; } } Gets compile error: No known class method for selector handleUrl ### OAuth Provider (Twitter, Github, ..): Fitbit ### OAuth Version: - [ ] Version 1 - [x] Version 2 ### OS (Please fill the version) : - [x] iOS : - [ ] OSX : - [ ] TVOS : - [ ] WatchOS : ### Installation method: - [ ] Carthage - [x] CocoaPods - [ ] Manually ### Library version: - [ ] head - [x] v1.2 (Swift 4.0) - [ ] v1.0.0 - [ ] v0.6 - [ ] other: (Please fill in the version you are using.) ### Xcode version: - [x] 9.0 (Swift 4.0) - [ ] 9.0 (Swift 3.2) - [ ] 8.x (Swift 3.x) - [ ] 8.0 (Swift 2.3) - [ ] 7.3.1 - [ ] other: (Please fill in the version you are using.) - [x] objective c
kerem closed this issue 2026-03-03 16:47:26 +03:00
Author
Owner

@phimage commented on GitHub (Mar 22, 2018):

maybe try with swift 3.2 because I do not try objc since swift 4

I make some methods prefixed with objc_ to handle some compatibility issue with objective c
in Sources/Objc.swift
I think maybe some annotations must be added, like @objc, and maybe some methods are missing

<!-- gh-comment-id:375364646 --> @phimage commented on GitHub (Mar 22, 2018): maybe try with swift 3.2 because I do not try objc since swift 4 I make some methods prefixed with objc_ to handle some compatibility issue with objective c in Sources/Objc.swift I think maybe some annotations must be added, like `@objc`, and maybe some methods are missing
Author
Owner

@lewis-smith commented on GitHub (Mar 26, 2018):

Ok thanks :)

As a work around I added a pass through method to my custom class:

@objc func handle(url: URL) {
    OAuthSwift.handle(url: url)
}

Which I can call from Objective C. If I am not missing something obvious I will leave this in place for now.

<!-- gh-comment-id:376310060 --> @lewis-smith commented on GitHub (Mar 26, 2018): Ok thanks :) As a work around I added a pass through method to my custom class: @objc func handle(url: URL) { OAuthSwift.handle(url: url) } Which I can call from Objective C. If I am not missing something obvious I will leave this in place for now.
Author
Owner

@ddaddy commented on GitHub (Nov 3, 2020):

I know this is an old issue, but I am also having this problem.
I am using 1.4.1 as suggested by the readme, but it seems OAuthSwift.handle(url: url) is not exposed to objc

<!-- gh-comment-id:721051861 --> @ddaddy commented on GitHub (Nov 3, 2020): I know this is an old issue, but I am also having this problem. I am using `1.4.1` as suggested by the readme, but it seems `OAuthSwift.handle(url: url)` is not exposed to `objc`
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/OAuthSwift#291
No description provided.