Skip to content

Commit 41a0888

Browse files
committed
Fix tvOS
Need to duplicate code to not make CocoaPods throw up with tvOS.
1 parent 60c6805 commit 41a0888

File tree

3 files changed

+78
-3
lines changed

3 files changed

+78
-3
lines changed

OAuth2.xcodeproj/project.pbxproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
DD0CCBAD1C4DC83A0044C4E3 /* OAuth2WebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD0CCBAC1C4DC83A0044C4E3 /* OAuth2WebViewController.swift */; };
3535
EA9758181B222CEA007744B1 /* OAuth2PasswordGrant.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA9758171B222CEA007744B1 /* OAuth2PasswordGrant.swift */; };
3636
EA97581E1B2242F9007744B1 /* OAuth2PasswordGrant.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA9758171B222CEA007744B1 /* OAuth2PasswordGrant.swift */; };
37-
EE1070321E5C793400250586 /* OAuth2CustomAuthorizer+iOS.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCCE4C8DC3CB7713E59BC1EE /* OAuth2CustomAuthorizer+iOS.swift */; };
3837
EE1070341E5C7A4200250586 /* OAuth2CustomAuthorizerUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE1070331E5C7A4200250586 /* OAuth2CustomAuthorizerUI.swift */; };
3938
EE1070351E5C7A4200250586 /* OAuth2CustomAuthorizerUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE1070331E5C7A4200250586 /* OAuth2CustomAuthorizerUI.swift */; };
4039
EE1070361E5C7A4200250586 /* OAuth2CustomAuthorizerUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE1070331E5C7A4200250586 /* OAuth2CustomAuthorizerUI.swift */; };
@@ -50,6 +49,7 @@
5049
EE2983751D40BE7600933CDD /* OAuth2AuthorizerUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE2983741D40BE7600933CDD /* OAuth2AuthorizerUI.swift */; };
5150
EE2983761D40BE7600933CDD /* OAuth2AuthorizerUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE2983741D40BE7600933CDD /* OAuth2AuthorizerUI.swift */; };
5251
EE2983771D40BE7600933CDD /* OAuth2AuthorizerUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE2983741D40BE7600933CDD /* OAuth2AuthorizerUI.swift */; };
52+
EE429D8E1E65721000BC6F67 /* OAuth2CustomAuthorizer+tvOS.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE429D8D1E65721000BC6F67 /* OAuth2CustomAuthorizer+tvOS.swift */; };
5353
EE4EBD871D7FF38200E6A9CA /* OAuth2Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE4EBD7E1D7FF38200E6A9CA /* OAuth2Tests.swift */; };
5454
EE4EBD881D7FF38200E6A9CA /* OAuth2AuthRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE4EBD7F1D7FF38200E6A9CA /* OAuth2AuthRequestTests.swift */; };
5555
EE4EBD891D7FF38200E6A9CA /* OAuth2ClientCredentialsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE4EBD811D7FF38200E6A9CA /* OAuth2ClientCredentialsTests.swift */; };
@@ -182,6 +182,7 @@
182182
EE29EABB195A0DB2008882C8 /* OAuth2DebugURLSessionDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OAuth2DebugURLSessionDelegate.swift; sourceTree = "<group>"; };
183183
EE29EABE195B0813008882C8 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
184184
EE3174EB1945E83100210E62 /* OAuth2ImplicitGrant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = OAuth2ImplicitGrant.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
185+
EE429D8D1E65721000BC6F67 /* OAuth2CustomAuthorizer+tvOS.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "OAuth2CustomAuthorizer+tvOS.swift"; sourceTree = "<group>"; };
185186
EE44F691194F2C7D0094AB8B /* OAuth2CodeGrant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = OAuth2CodeGrant.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
186187
EE450CD31AD57578008AB6FC /* p2.OAuth2.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = p2.OAuth2.podspec; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
187188
EE4EBD7E1D7FF38200E6A9CA /* OAuth2Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OAuth2Tests.swift; sourceTree = "<group>"; };
@@ -262,6 +263,7 @@
262263
isa = PBXGroup;
263264
children = (
264265
6598543F1C5B3B4000237D39 /* OAuth2Authorizer+tvOS.swift */,
266+
EE429D8D1E65721000BC6F67 /* OAuth2CustomAuthorizer+tvOS.swift */,
265267
);
266268
path = tvOS;
267269
sourceTree = "<group>";
@@ -652,14 +654,14 @@
652654
EEB9A97E1D86C34E0022EF66 /* OAuth2Response.swift in Sources */,
653655
EEFD23531C9ED9E400727DCF /* OAuth2ClientCredentialsReddit.swift in Sources */,
654656
6598545A1C5B3CA700237D39 /* OAuth2PasswordGrant.swift in Sources */,
657+
EE429D8E1E65721000BC6F67 /* OAuth2CustomAuthorizer+tvOS.swift in Sources */,
655658
659854551C5B3CA700237D39 /* OAuth2CodeGrantFacebook.swift in Sources */,
656659
659854611C5B3CB900237D39 /* Keychain.swift in Sources */,
657660
EEB9A9851D86D36A0022EF66 /* OAuth2RequestPerformer.swift in Sources */,
658661
659854561C5B3CA700237D39 /* OAuth2CodeGrantLinkedIn.swift in Sources */,
659662
6598545D1C5B3CAB00237D39 /* OAuth2Error.swift in Sources */,
660663
EE2983721D40B83600933CDD /* OAuth2.swift in Sources */,
661664
EE20118E1E44D0BD00913FA7 /* OAuth2DataLoaderSessionTaskDelegate.swift in Sources */,
662-
EE1070321E5C793400250586 /* OAuth2CustomAuthorizer+iOS.swift in Sources */,
663665
65EC05E21C9050CB00DE9186 /* OAuth2KeychainAccount.swift in Sources */,
664666
6598545C1C5B3CAB00237D39 /* OAuth2DebugURLSessionDelegate.swift in Sources */,
665667
6598544E1C5B3C9500237D39 /* OAuth2Authorizer+tvOS.swift in Sources */,

Sources/iOS/OAuth2CustomAuthorizer+iOS.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// See the License for the specific language governing permissions and
1818
// limitations under the License.
1919
//
20-
#if os(iOS) || os(tvOS)
20+
#if os(iOS)
2121

2222
import Foundation
2323
import UIKit
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//
2+
// OAuth2CustomAuthorizer+tvOS.swift
3+
// OAuth2
4+
//
5+
// Created by Amaury David on 08/02/2017.
6+
// Copyright (c) 2017 Pascal Pfiffner. All rights reserved.
7+
//
8+
// Licensed under the Apache License, Version 2.0 (the "License");
9+
// you may not use this file except in compliance with the License.
10+
// You may obtain a copy of the License at
11+
//
12+
// http://www.apache.org/licenses/LICENSE-2.0
13+
//
14+
// Unless required by applicable law or agreed to in writing, software
15+
// distributed under the License is distributed on an "AS IS" BASIS,
16+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
// See the License for the specific language governing permissions and
18+
// limitations under the License.
19+
//
20+
#if os(tvOS)
21+
22+
import Foundation
23+
import UIKit
24+
#if !NO_MODULE_IMPORT
25+
import Base
26+
#endif
27+
28+
29+
/**
30+
An iOS and tvOS-specific implementation of the `OAuth2CustomAuthorizerUI` protocol which modally presents the login controller.
31+
*/
32+
public class OAuth2CustomAuthorizer: OAuth2CustomAuthorizerUI {
33+
34+
private var presentingController: UIViewController?
35+
36+
public init() { }
37+
38+
39+
// MARK: - OAuth2CustomAuthorizerUI
40+
41+
/**
42+
Modally present the login controller from the given context.
43+
44+
- parameter loginController: The controller to present modally.
45+
- parameter context: The parent controller to use to present the login controller.
46+
- parameter animated: Whether the presentation should be animated.
47+
*/
48+
public func present(loginController: AnyObject, fromContext context: AnyObject?, animated: Bool) throws {
49+
guard let parentController = context as? UIViewController else {
50+
throw context == nil ? OAuth2Error.noAuthorizationContext : OAuth2Error.invalidAuthorizationContext
51+
}
52+
guard let controller = loginController as? UIViewController else {
53+
throw OAuth2Error.invalidLoginController(actualType: String(describing: type(of: loginController)),
54+
expectedType: String(describing: UIViewController.self))
55+
}
56+
57+
presentingController = parentController
58+
presentingController?.present(controller, animated: animated)
59+
}
60+
61+
62+
/**
63+
Dismiss the presented login controller if any.
64+
65+
- parameter animated: Whether the dismissal should be animated.
66+
*/
67+
public func dismissLoginController(animated: Bool) {
68+
presentingController?.dismiss(animated: animated)
69+
presentingController = nil
70+
}
71+
}
72+
73+
#endif

0 commit comments

Comments
 (0)