Ключ GIPHY API не устанавливается - PullRequest
1 голос
/ 08 июня 2019

Я пытаюсь включить API GIPHY в свой проект.

В своем AppDelegate я установил API-ключ для открытого бета-ключа (просто для его тестирования):

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

    SwiftyGiphyAPI.shared.apiKey = "dc6zaTOxFJmzC"


    // Override point for customization after application launch.
    return true
}

И это из открытого класса SwiftyGiphyAPI:

public static let publicBetaKey = "dc6zaTOxFJmzC"

/// Access the Giphy API through the shared singleton.
public static let shared: SwiftyGiphyAPI = SwiftyGiphyAPI()

/// Before you can use SwiftyGiphy, you need to set your API key.
public var apiKey: String? {
    didSet {

        if apiKey == SwiftyGiphyAPI.publicBetaKey
        {
            print("****************************************************************************************************************************")
            print("*                                                                                                                          *")
            print("*     IMPORTANT: You seem to be using Giphy's public beta key. Please change this to a production key before shipping.     *")
            print("*     Apply for one here: http://api.giphy.com/submit                                                                      *")
            print("*                                                                                                                          *")
            print("****************************************************************************************************************************")
            print("")
        }
    }
}

И когда открывается Контроллер, секция трендов должна показывать трендовые GIF, это начало этой функции:

   func getTrending(limit: Int = 25, rating: SwiftyGiphyAPIContentRating = .pg13, offset: Int? = nil, completion: GiphyMultipleGIFResponseBlock?)
{
    guard apiKey != nil || !isUsingDefaultAPIBase else {
        print("ATTENTION: You need to set your Giphy API key before using SwiftyGiphy.")

        completion?(networkError(description: NSLocalizedString("You need to set your Giphy API key before using SwiftyGiphy.", comment: "You need to set your Giphy API key before using SwiftyGiphy.")), nil)
        return
    }

Я получаю утверждение печати, что You need to set your Giphy API key before using SwiftyGiphy.

Я думаю, это потому, что SwiftyGiphyAPI.shared.apiKey по-прежнему не является обязательным, поэтому SwiftyGiphyAPI читается как ноль.Я перепробовал некоторые дополнительные цепочки, но, возможно, я сделал это неправильно.

Я уверен, что я пропускаю простое исправление.

Кроме того, вот ссылка на документы GIPHY, еслиэто помогает: GIPHY Docs

Заранее спасибо за помощь!

...