【问题标题】:What to do when I get the unauthorized error in Parse Swift 2.2当我在 Parse Swift 2.2 中遇到未经授权的错误时该怎么办
【发布时间】:2016-07-26 14:19:44
【问题描述】:

我正在使用空白应用 Parse 下载和 back4app。我将客户端和应用程序 ID 放在 AppDelegate 上并运行应用程序,但出现以下错误:

"2016-07-26 11:08:29.681 ParseStarterProject-Swift[1464:107722] [错误]:未经授权(代码:0,版本:1.12.0)2016-07-26 11:08:29.682 ParseStarterProject-Swift [1464:107719] [错误]:未能 最终运行命令并出现错误:错误域 = 解析代码 = 0 “未经授权” UserInfo={错误=未经授权, NSLocalizedDescription=未授权,临时=0}"

ViewController 为空

AppDelegate:

import UIKit

import Parse

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

//--------------------------------------
// MARK: - UIApplicationDelegate
//--------------------------------------

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Enable storing and querying data from Local Datastore.
    // Remove this line if you don't want to use Local Datastore features or want to use cachePolicy.
    Parse.enableLocalDatastore()
     Parse.setApplicationId("ciBn93EohqEq7WLJEAByrrVFfR6B3Fu98UJgRteY",clientKey: "KHKJgfJhSLAktjqmKHRhlaUtBhtzZELsdwexpIdf")

    PFUser.enableAutomaticUser()

    let defaultACL = PFACL();

    // If you would like all objects to be private by default, remove this line.
    defaultACL.publicReadAccess = true

    PFACL.setDefaultACL(defaultACL, withAccessForCurrentUser: true)

    if application.applicationState != UIApplicationState.Background {
        // Track an app open here if we launch with a push, unless
        // "content_available" was used to trigger a background push (introduced in iOS 7).
        // In that case, we skip tracking here to avoid double counting the app-open.

        let preBackgroundPush = !application.respondsToSelector("backgroundRefreshStatus")
        let oldPushHandlerOnly = !self.respondsToSelector("application:didReceiveRemoteNotification:fetchCompletionHandler:")
        var noPushPayload = false;
        if let options = launchOptions {
            noPushPayload = options[UIApplicationLaunchOptionsRemoteNotificationKey] != nil;
        }
        if (preBackgroundPush || oldPushHandlerOnly || noPushPayload) {
            PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)
        }
    }

    return true
}

//--------------------------------------
// MARK: Push Notifications
//--------------------------------------

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
    let installation = PFInstallation.currentInstallation()
    installation.setDeviceTokenFromData(deviceToken)
    installation.saveInBackground()

    PFPush.subscribeToChannelInBackground("") { (succeeded: Bool, error: NSError?) in
        if succeeded {
            print("ParseStarterProject successfully subscribed to push notifications on the broadcast channel.\n");
        } else {
            print("ParseStarterProject failed to subscribe to push notifications on the broadcast channel with error = %@.\n", error)
        }
    }
}

func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
    if error.code == 3010 {
        print("Push notifications are not supported in the iOS Simulator.\n")
    } else {
        print("application:didFailToRegisterForRemoteNotificationsWithError: %@\n", error)
    }
}

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
    PFPush.handlePush(userInfo)
    if application.applicationState == UIApplicationState.Inactive {
        PFAnalytics.trackAppOpenedWithRemoteNotificationPayload(userInfo)
    }
}
}

谢谢

【问题讨论】:

  • 您永远不应该发布您的应用程序 ID 和客户端密钥。您应该立即重新生成新密钥。
  • 谢谢,但这只是一个测试

标签: ios swift parsing swift2 back4app


【解决方案1】:

我发现你应该怎么做,只是改变

这个

 Parse.setApplicationId("APP_ID",clientKey: "CLIENT_KEY")

有了这个

let configuration = ParseClientConfiguration{
        $0.applicationId = "APP_ID"
        $0.clientKey = "CLIENT_KEY"
        $0.server = "https://parseapi.back4app.com/"
    }

服务器地址还是一样

【讨论】:

    【解决方案2】:

    我认为你的 appid 和客户端密钥一定有问题。

    【讨论】:

    • 这可能更适合作为评论。您能否详细说明这是如何回答问题的?
    猜你喜欢
    • 1970-01-01
    • 2021-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-13
    • 1970-01-01
    • 1970-01-01
    • 2021-07-05
    相关资源
    最近更新 更多