Skip to content

Commit

Permalink
Fix tvOS
Browse files Browse the repository at this point in the history
Need to duplicate code to not make CocoaPods throw up with tvOS.
  • Loading branch information
p2 committed Feb 28, 2017
1 parent 60c6805 commit 41a0888
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 3 deletions.
6 changes: 4 additions & 2 deletions OAuth2.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
DD0CCBAD1C4DC83A0044C4E3 /* OAuth2WebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD0CCBAC1C4DC83A0044C4E3 /* OAuth2WebViewController.swift */; };
EA9758181B222CEA007744B1 /* OAuth2PasswordGrant.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA9758171B222CEA007744B1 /* OAuth2PasswordGrant.swift */; };
EA97581E1B2242F9007744B1 /* OAuth2PasswordGrant.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA9758171B222CEA007744B1 /* OAuth2PasswordGrant.swift */; };
EE1070321E5C793400250586 /* OAuth2CustomAuthorizer+iOS.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCCE4C8DC3CB7713E59BC1EE /* OAuth2CustomAuthorizer+iOS.swift */; };
EE1070341E5C7A4200250586 /* OAuth2CustomAuthorizerUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE1070331E5C7A4200250586 /* OAuth2CustomAuthorizerUI.swift */; };
EE1070351E5C7A4200250586 /* OAuth2CustomAuthorizerUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE1070331E5C7A4200250586 /* OAuth2CustomAuthorizerUI.swift */; };
EE1070361E5C7A4200250586 /* OAuth2CustomAuthorizerUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE1070331E5C7A4200250586 /* OAuth2CustomAuthorizerUI.swift */; };
Expand All @@ -50,6 +49,7 @@
EE2983751D40BE7600933CDD /* OAuth2AuthorizerUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE2983741D40BE7600933CDD /* OAuth2AuthorizerUI.swift */; };
EE2983761D40BE7600933CDD /* OAuth2AuthorizerUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE2983741D40BE7600933CDD /* OAuth2AuthorizerUI.swift */; };
EE2983771D40BE7600933CDD /* OAuth2AuthorizerUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE2983741D40BE7600933CDD /* OAuth2AuthorizerUI.swift */; };
EE429D8E1E65721000BC6F67 /* OAuth2CustomAuthorizer+tvOS.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE429D8D1E65721000BC6F67 /* OAuth2CustomAuthorizer+tvOS.swift */; };
EE4EBD871D7FF38200E6A9CA /* OAuth2Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE4EBD7E1D7FF38200E6A9CA /* OAuth2Tests.swift */; };
EE4EBD881D7FF38200E6A9CA /* OAuth2AuthRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE4EBD7F1D7FF38200E6A9CA /* OAuth2AuthRequestTests.swift */; };
EE4EBD891D7FF38200E6A9CA /* OAuth2ClientCredentialsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE4EBD811D7FF38200E6A9CA /* OAuth2ClientCredentialsTests.swift */; };
Expand Down Expand Up @@ -182,6 +182,7 @@
EE29EABB195A0DB2008882C8 /* OAuth2DebugURLSessionDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OAuth2DebugURLSessionDelegate.swift; sourceTree = "<group>"; };
EE29EABE195B0813008882C8 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
EE3174EB1945E83100210E62 /* OAuth2ImplicitGrant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = OAuth2ImplicitGrant.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
EE429D8D1E65721000BC6F67 /* OAuth2CustomAuthorizer+tvOS.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "OAuth2CustomAuthorizer+tvOS.swift"; sourceTree = "<group>"; };
EE44F691194F2C7D0094AB8B /* OAuth2CodeGrant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = OAuth2CodeGrant.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
EE450CD31AD57578008AB6FC /* p2.OAuth2.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = p2.OAuth2.podspec; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
EE4EBD7E1D7FF38200E6A9CA /* OAuth2Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OAuth2Tests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -262,6 +263,7 @@
isa = PBXGroup;
children = (
6598543F1C5B3B4000237D39 /* OAuth2Authorizer+tvOS.swift */,
EE429D8D1E65721000BC6F67 /* OAuth2CustomAuthorizer+tvOS.swift */,
);
path = tvOS;
sourceTree = "<group>";
Expand Down Expand Up @@ -652,14 +654,14 @@
EEB9A97E1D86C34E0022EF66 /* OAuth2Response.swift in Sources */,
EEFD23531C9ED9E400727DCF /* OAuth2ClientCredentialsReddit.swift in Sources */,
6598545A1C5B3CA700237D39 /* OAuth2PasswordGrant.swift in Sources */,
EE429D8E1E65721000BC6F67 /* OAuth2CustomAuthorizer+tvOS.swift in Sources */,
659854551C5B3CA700237D39 /* OAuth2CodeGrantFacebook.swift in Sources */,
659854611C5B3CB900237D39 /* Keychain.swift in Sources */,
EEB9A9851D86D36A0022EF66 /* OAuth2RequestPerformer.swift in Sources */,
659854561C5B3CA700237D39 /* OAuth2CodeGrantLinkedIn.swift in Sources */,
6598545D1C5B3CAB00237D39 /* OAuth2Error.swift in Sources */,
EE2983721D40B83600933CDD /* OAuth2.swift in Sources */,
EE20118E1E44D0BD00913FA7 /* OAuth2DataLoaderSessionTaskDelegate.swift in Sources */,
EE1070321E5C793400250586 /* OAuth2CustomAuthorizer+iOS.swift in Sources */,
65EC05E21C9050CB00DE9186 /* OAuth2KeychainAccount.swift in Sources */,
6598545C1C5B3CAB00237D39 /* OAuth2DebugURLSessionDelegate.swift in Sources */,
6598544E1C5B3C9500237D39 /* OAuth2Authorizer+tvOS.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Sources/iOS/OAuth2CustomAuthorizer+iOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
#if os(iOS) || os(tvOS)
#if os(iOS)

import Foundation
import UIKit
Expand Down
73 changes: 73 additions & 0 deletions Sources/tvOS/OAuth2CustomAuthorizer+tvOS.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//
// OAuth2CustomAuthorizer+tvOS.swift
// OAuth2
//
// Created by Amaury David on 08/02/2017.
// Copyright (c) 2017 Pascal Pfiffner. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#if os(tvOS)

import Foundation
import UIKit
#if !NO_MODULE_IMPORT
import Base
#endif


/**
An iOS and tvOS-specific implementation of the `OAuth2CustomAuthorizerUI` protocol which modally presents the login controller.
*/
public class OAuth2CustomAuthorizer: OAuth2CustomAuthorizerUI {

private var presentingController: UIViewController?

public init() { }


// MARK: - OAuth2CustomAuthorizerUI

/**
Modally present the login controller from the given context.

- parameter loginController: The controller to present modally.
- parameter context: The parent controller to use to present the login controller.
- parameter animated: Whether the presentation should be animated.
*/
public func present(loginController: AnyObject, fromContext context: AnyObject?, animated: Bool) throws {
guard let parentController = context as? UIViewController else {
throw context == nil ? OAuth2Error.noAuthorizationContext : OAuth2Error.invalidAuthorizationContext
}
guard let controller = loginController as? UIViewController else {
throw OAuth2Error.invalidLoginController(actualType: String(describing: type(of: loginController)),
expectedType: String(describing: UIViewController.self))
}

presentingController = parentController
presentingController?.present(controller, animated: animated)
}


/**
Dismiss the presented login controller if any.

- parameter animated: Whether the dismissal should be animated.
*/
public func dismissLoginController(animated: Bool) {
presentingController?.dismiss(animated: animated)
presentingController = nil
}
}

#endif

0 comments on commit 41a0888

Please sign in to comment.