【问题标题】:Use of unresolved identifier 'url'使用未解析的标识符“url”
【发布时间】:2016-12-21 00:38:03
【问题描述】:

我对 API 完全陌生,并且正在关注 appcoda 上的本教程 https://www.appcoda.com/dropbox-api-tutorial/

一直很顺利,但是我遇到了一个问题,鉴于我是新手,我不知道如何解决它。

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.

        let appKey = "n00nzv68gtxk6c9"      // Set your own app key value here.
        let appSecret = "itumv0icksr7yj6"   // Set your own app secret value here.

        let dropboxSession = DBSession(appKey: appKey, appSecret: appSecret, root: kDBRootDropbox)
        DBSession.setShared(dropboxSession)

        return true

        if DBSession.sharedSession().handleOpenURL(url) {
            if DBSession.shared().isLinked() {
                NotificationCenter.defaultCenter.postNotificationName("didLinkToDropboxAccountNotification", object: nil)
                return true
            }
        }

        return false

    }

问题出在一行

if DBSession.sharedSession().handleOpenURL(url) {

我在哪里得到错误

Use of unresolved identifier 'url'

我需要做什么?

【问题讨论】:

  • 您需要在尝试使用之前正确声明并初始化一个名为url 的变量,或者您需要将url 替换为另一个URL 类型变量。
  • 应该是什么类型的?
  • 另请注意,if DBSession... 块与您放入的委托方法完全不同。
  • “它应该是什么类型?” - 转到DBSession 类的文档页面并查看handleOpenURL 方法的信息。它会告诉你它应该是什么类型。
  • @rmaddy 我不明白你的意思:“另请注意,if DBSession... 块与您放入的委托方法完全不同”

标签: swift swift3 dropbox-api


【解决方案1】:

根据教程,您需要在 AppDelegate.swift 中使用正确的委托方法

// handle custom application schemes
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
    if DBSession.sharedSession().handleOpenURL(url) {
        print("Url defined as \( url)")
    }
}

【讨论】:

  • 谢谢,这是个愚蠢的错误
猜你喜欢
  • 2018-03-12
  • 1970-01-01
  • 1970-01-01
  • 2016-02-25
  • 2016-07-17
  • 2016-04-29
  • 2017-02-27
相关资源
最近更新 更多