TheQKit 1.2.9

TheQKit 1.2.9

Jonathan Spohn 维护。



 
依赖项
Alamofire~> 4.9.1
lottie-ios>= 0
SwiftyJSON~> 5.0.0
ObjectMapper~> 3.5.2
Toast-Swift~> 5.0.1
SwiftyAttributes~> 5.1.1
Kingfisher~> 5.13.2
 

TheQKit 1.2.9

  • Spohn

TheQKit

Version Platform

什么新功能? 1.2.7

1.2.7添加了“完整网络体验”路由,可以在不更新SDK的情况下包含新的游戏功能。 - 向初始化函数中添加了一个名为'partnerName'的参数,该参数由合作伙伴管理控制台定义。 - 在TQKGameOptions中添加了一个名为'fullWebExp'的参数,当设置为'true'时,将使用该模式运行游戏。

将这些参数添加到初始化或游戏选项中将允许网页玩家控制游戏体验 - 即使没有应用程序更新也可以使用新的游戏模式。

1.2.5向TQKGameOptions中添加了一个可选参数alwaysUseHLS,当设置为true时,将覆盖默认行为,尽可能使用LLIS。

示例

要运行示例项目,请克隆存储库,然后首先从示例目录中运行pod install

登录/身份验证和设置说明

  1. 始终将包标识符更改为与您的开发者帐户关联的标识符。

  2. 要使用示例应用,无论是 Firebase 还是 AccountKit(即将推出“用 Apple 登录”功能),都需要在应用中使用和设置,并实现登录流程。一旦用户通过这些服务进行了身份验证,您就可以将相关信息传递给 SDK,以在 The Q 平台上创建用户。

    2a) 对于 Firebase,这包括添加 GoogleServices.plist 文件以及任何 .info.plist 的修改

安装

TheQKit 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中

pod 'TheQKit'

如果您是从本地源添加

pod 'TheQKit', :path => '<path to directory with the .podspec>'

入门

初始化

在 AppDelegate.swift 中导入 TheQKit,并在 application:didFinishLaunchingWithOptions: 中使用支持团队提供的令牌初始化 TheQKit

THEQKIT_TOKEN 允许 TheQKit 仅可见此租户的游戏,是必需的。

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    TheQKit.initialize(baseUrl: "<Provided Base Url>", webPlayerUrl: "<Provided Web Player Url>",token: "<Provided Account Token>")
    
    //Optional - Disable the built in profanity filter on freeform user answers
    //TheQKit.disableProfanityFilter()
    
    //Optional - Allow users to screen record during games
    //TheQKit.enableScreenRecording()
}

初始化时提供的参数的完整列表以及默认值

/// - Parameters:
///     - baseURL: *Required* base URL to partners domain 
///     - locale: *Optional* language / region 
///     - moneySymbol: *Optional* meant to always match the one the locale would use
///     - appName: *Optional* name of the app to be shown to users 
///     - webPlayerURL: *Optional* url for alternative / optional webplayer (provided by Stream Live, Inc.) 
///     - token: *Required* partner key (provided by Stream Live, Inc.) 
public class func initialize(baseURL:String, locale:String? = "en_US", moneySymbol:String? = "$", appName:String? = "The Q", webPlayerURL:String? = nil, token : String){..}

用户身份验证

Account Kit 的集成必须在应用端完成,在验证那些提供者之后,将令牌字符串和账户 ID 传递以登录现有用户或进入用户创建流程

用 Apple 登录

if let token = appleIDCredential.identityToken?.base64EncodedString() {
    let userIdentifier = appleIDCredential.user
    
    TheQKit.LoginQUserWithApple(userID: userIdentifier, identityString: token) { (success) in
        //success : Bool ... if user successfully is logged in, if no user exist will be false and account creation flow launches
    }
}

Account Kit: 已弃用:随着 AccountKit 的关闭,此方法将不再使用,但对于现有用户或未设置 Firebase 电话号码的应用而言仍然可用。

let token = AKFAccountKit(responseType: .accessToken).currentAccessToken
let accountID:String = token!.accountID
let tokenString:String = token!.tokenString

TheQKit.LoginQUserWithAK(accountID: accountID, tokenString: tokenString) { (success) in
    //success : Bool ... if user successfully is logged in, if no user exist will be false and account creation flow launches
}

Firebase:有几种不同的方法可以完成同样的任务,最终都会得到一个用户 ID 和令牌,这将传递给 TheQKit

extension YourVC: FUIAuthDelegate {
    func authUI(_ authUI: FUIAuth, didSignInWith authDataResult: AuthDataResult?, url: URL?, error: Error?) {

        if let user = authDataResult?.user {
            user.getIDTokenResult(completion: { (result, error) in
                let token = result?.token
                let userId:String = user.uid

                TheQKit.LoginQUserWithFirebase(userId: userId, tokenString: token) { (success) in
                    //success : Bool ... if user successfully is logged in, if no user exist will be false and account creation flow launches
                }
            })
        }
    }
}

此外,您还可以跳过用户名选择并提供一个用户可能已经与您的应用关联的用户名。如果已被占用,则数字将递增

TheQKit.LoginQUserWithApple(userID: userIdentifier, identityString: token, username : "username") { (success) in
     //success : Bool ... if user successfully is logged in, no account creation flow
}

*DEPRECATED*
TheQKit.LoginQUserWithAK(accountID: "accountID", tokenString: "tokenString", username : "username") { (success) in
    //success : Bool ... if user successfully is logged in, no account creation flow
}

TheQKit.LoginQUserWithFirebase(userId: "uid", tokenString: "tokenString", username : "username") { (success) in
    //success : Bool ... if user successfully is logged in, if no user exist will be false and account creation flow launches
}

注销并清除存储的用户

TheQKit.LogoutQUser()

启动 / 玩游戏

版本 1.1.4 新增,在启动游戏时增加可选的 gameOptions 参数,允许配置各种 UI 元素

///     - logoOverride: *Optional* the logo in the upper right of the game, will override the default or the network badge from a game theme if avaliable
///     - colorCode: *Optional* override the color theme of the game - supercedes useThemeColors
///     - playerBackgroundColor: *Optinal* sets the backgroundcolor of the player, default to clear
///     - useThemeAsBackground: *Optional* tells the player to use the theme image as a background. Note: leave playerBackgroundColor as clear to see this
///     - useThemeColors: *Optional* Overrides the text color and background overloay of questions / results with default color code, text color code from the theme object configured from the admin portal
///     - correctBackgroundColor: *Optional* overrides the default color of the correct screen
///     - incorrectBackgroundColor: *Optional* overrides the default color of the incorrect screen
///     - questionBackgroundAlpha: *Optional* allows the opacity of the question/incorrect/correct screens to be changes. (0.0 .. 1.0)
///     - isEliminationDisabled: *Optional* Users will never know if they are eliminated or not, simulates a non-elimination game mode
///     - useWebPlayer: *Optional* toggles from using the native AVPlayer to using an embedded webplayer via WebKit. MUST HAVE "webPlayerURL" DEFINED IN TheQKit.initialize(...) IN THE APP DELEGATE TO WORK
///     - alwaysUseHLS: *Optional* forces the player to use the HLS url even if the LLHLS url is present - default behavior uses LLHLS if present.

let options = TQKGameOptions(logoOverride: <#T##UIImage?#>,
                            colorCode: <#T##String?#>,
                            playerBackgroundColor: <#T##UIColor?#>,
                            useThemeAsBackground: <#T##Bool?#>,
                            useThemeColors: <#T##Bool?#>,
                            correctBackgroundColor: <#T##UIColor?#>,
                            incorrectBackgroundColor: <#T##UIColor?#>,
                            questionBackgroundAlpha: <#T##CGFloat?#>,
                            isEliminationDisabled: <#T##Bool?#>,
                            useWebPlayer: <#T##Bool?#>,
                            alwaysUseHLS: <#T##Bool?#>)

玩游戏 - 带UI

可以将用于显示游戏“卡片”的计划控制器填充到任何容器视图中。当游戏处于激活状态且存在已登录用户时,可以点击这些卡片。

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "name_of_your_seque" {
        let connectContainerViewController = segue.destination as UIViewController
        TheQKit.showCardsController(fromViewController: connectContainerViewController, gameOptions: options)
    }
}

玩游戏 - 不带UI

要用 Q Kit 玩游戏,初始化后,您需要检查并启动游戏

TheQKit.CheckForGames { (isActive, gamesArray) in
    //isActive : Bool ... are any games returned currently active
    //gamesArray : [TQKGame]? ... active and non active games
}
TheQKit.LaunchGame(theGame : TQKGame, gameOptions: options) //Checks if specified game is active and launches it
TheQKit.LaunchActiveGame(gameOptions: options)            //checks for an active game and launches it if avaliable

更新用户名 / 电子邮件 / 电话

更新用户名

TheQKit.updateUsername(username: " ") { (success, errorMsg) in
     //success : Bool ... if user record is updates succesfully
     //errorMsg : error msg if one
}

使用电子邮件、电话号码或两者同时更新用户信息。

TheQKit.updateUser(email:"<Optional Email>", phoneNumber:"<Optional Phone#>") { (success, errorMsg) in
     //success : Bool ... if user record is updates succesfully
     //errorMsg : error msg if one
}

自定义颜色主题

游戏有默认的颜色主题,如果您希望覆盖它,请将 colorCode 作为十六进制字符串传递给启动函数

TheQKit.LaunchGame(theGame : TQKGame, colorCode : "#E63462") 
TheQKit.LaunchActiveGame(colorCode : "#E63462")         

获取 $

赢得金钱的用户可以申请提现。开始此申请请调用以下方法。将显示一个请求PayPal电子邮件地址的对话框,然后再显示请求成功/失败

TheQKit.CashOutWithUI()

或者将电子邮件传递给此方法以跳过默认对话框

TheQKit.CashOutNoUI(email: String)

排行榜

//This function retrieves scores for each category for the signed in user
TheQKit.getCurrentUserScores { (success, scores) in
    //success
    //scores: user scores object
}

//This function retrieves the current leaderboard, seperated into season info and category/scores
TheQKit.getCurrentLeaderboard { (success, lb) in
    //success
    //lb: leaderboard object containing season and category info
}

//Combination function that will return either
TheQKit.getCurrentLeaderboardAndUserScores { (success, lb, scores) in
    //success
    //lb: leaderboard object containing season and category info
    //scores: user scores object
}

可观察的键

发生在游戏中的事件;添加观察者以添加自定义事件跟踪。为了易于使用,请添加扩展或使用字符串字面量。每个事件都返回一个与事件相关的[字符串:任意]字典的元数据

NotificationCenter.default.addObserver(self, selector: #selector(errorSubmittingAnswer), name: .errorSubmittingAnswer, object: nil)

extension Notification.Name {
    static let choiceSelected = Notification.Name("TQK_GAME_CHOICE_SELECTED")
    static let errorSubmittingAnswer = Notification.Name("TQK_GAME_ERROR_SUB_ANSWER")
    static let screenRecordingDetected = Notification.Name("TQK_GAME_SCREEN_RECORDING")
    static let airplayDetected = Notification.Name("TQK_GAME_AIRPLAY")
    static let correctAnswerSubmitted = Notification.Name("TQK_GAME_CORRECT_ANS_SUB")
    static let incorrectAnswerSubmitted = Notification.Name("TQK_GAME_WRONG_ANS_SUB")
    static let enteredGame = Notification.Name("TQK_ENTERED_GAME")
    static let gameWon = Notification.Name("TQK_GAME_WON")
}

作者

Spohn,[邮箱地址可见,请点击显示]和Stream Live, Inc.的可爱的人们。

许可

版权所有 (c) 2020 Stream Live, Inc.