Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 线程1:EXC_BAD_访问(代码=1,地址=0x0)在swift中工作时尝试登录spotify_Ios_Swift_Xcode_Spotify - Fatal编程技术网

Ios 线程1:EXC_BAD_访问(代码=1,地址=0x0)在swift中工作时尝试登录spotify

Ios 线程1:EXC_BAD_访问(代码=1,地址=0x0)在swift中工作时尝试登录spotify,ios,swift,xcode,spotify,Ios,Swift,Xcode,Spotify,代码: 该应用程序编译良好,并在模拟器IPhone上启动。登录Spotify的按钮起作用,并打开一个Safari实例,提示用户登录Spotify 一旦用户登录,它就会请求权限。一旦用户接受权限,应用程序将在appDelegate类的第16行崩溃,并出现以下错误: 线程1:EXC\u BAD\u访问代码=1,地址=0x0 我在网上读过这篇文章,人们说这相当于一个空指针异常,但我找不到导致这个错误的原因。有人能找到错误吗 编辑:感谢那些回应的人!以下是我的控制台输出: objc[19082]:类VC

代码:

该应用程序编译良好,并在模拟器IPhone上启动。登录Spotify的按钮起作用,并打开一个Safari实例,提示用户登录Spotify

一旦用户登录,它就会请求权限。一旦用户接受权限,应用程序将在appDelegate类的第16行崩溃,并出现以下错误:

线程1:EXC\u BAD\u访问代码=1,地址=0x0

我在网上读过这篇文章,人们说这相当于一个空指针异常,但我找不到导致这个错误的原因。有人能找到错误吗

编辑:感谢那些回应的人!以下是我的控制台输出:

objc[19082]:类VCWeakObjectHolder在两个 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/privateframes/AVConference.framework/Frameworks/ViceroyTrace.framework/ViceroyTrace 0x12b9174d0和 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/privateframes/AVConference.framework/AVConference 0x12aa65e38。将使用其中一个。哪一个是未定义的。 测试2018-04-15 13:33:50.341600-0400拆分器SWIFT3[19082:1059086] [AXRun PID]请求PID的客户端:-1名称: 2018-04-15 13:33:50.441522-0400拆分器SWIFT3[19082:1058985][MC] systemgroup.com.apple.configurationprofiles的系统组容器 路径是 /用户/videolabn/Library/Developer/CoreSimulator/Devices/CEC32A65-63E0-4499-AB25-6BD13A7AE013/data/Containers/Shared/SystemGroup/SystemGroup.com.apple.configurationprofiles 2018-04-15 13:33:50.442782-0400 SplitterSwift3[19082:1058985][MC] 从私人有效用户设置读取。2018-04-15 13:33:50.536744-0400 SplitterSwift3[19082:1058985][App]如果我们在 真正的预提交处理程序我们实际上无法添加任何新的fences 到CA限制lldb

iOS 10中不推荐使用UIApplicationLegate函数

从iOS 11.3开始,使用此功能的应用程序在被调用时似乎会崩溃。解决办法是使用替代品

此外,无需为UserDefaults调用synchronize

iOS 10中不推荐使用UIApplicationLegate函数

从iOS 11.3开始,使用此功能的应用程序在被调用时似乎会崩溃。解决办法是使用替代品


此外,不需要为UserDefaults调用synchronize

,如果您设置了,它会在哪一行停止?控制台中是否有完整的崩溃日志?因为我看到了一些!强制取消覆盖可能导致此问题或其他任何问题。感谢@Larme的评论!我是一个傻瓜,我如何找到完整的崩溃日志?谢谢你的评论@MichaelHulet!我设置了一个常规异常断点,但在同一行上仍然得到相同的错误!是我做错了什么,还是我只是犯了同样的错误?我们怎么知道第16行是什么。从文件顶部开始计数,从方法开始计数,包括空行,不包括空行,包括注释,计数时不包括注释。。。。第16行是什么?如果设置了,它会停在哪一行?控制台中是否有完整的崩溃日志?因为我看到了一些!强制取消覆盖可能导致此问题或其他任何问题。感谢@Larme的评论!我是一个傻瓜,我如何找到完整的崩溃日志?谢谢你的评论@MichaelHulet!我设置了一个常规异常断点,但在同一行上仍然得到相同的错误!是我做错了什么,还是我只是犯了同样的错误?我们怎么知道第16行是什么。从文件顶部开始计数,从方法开始计数,包括空行,不包括空行,包括注释,计数时不包括注释。。。。第16行是什么?谢谢你的帮助!我实现了这个更改,当我在spotify premission屏幕上按OK时,没有出现任何错误。它只是停止了。但是,应用程序不会崩溃,因此可能是我如何实现spotify api的问题。它是否返回到您的应用程序?发布LoginSucessFull通知时,您的应用程序是否执行了某些操作?-检查您正在观察的通知名称的拼写;您发布的通知末尾有一个双l。最好是在一个地方创建通知名称并引用它们,而不是在可能存在不一致的地方使用文本字符串。感谢您的帮助!我实现了这个更改,当我在spotify premission屏幕上按OK时,没有出现任何错误。它只是停止了。但是,该应用程序不会崩溃,因此可能是我如何实现spotify api的问题。是吗 返回到你的应用程序?发布LoginSucessFull通知时,您的应用程序是否执行了某些操作?-检查您正在观察的通知名称的拼写;您发布的通知末尾有一个双l。最好在一个地方创建通知名称并引用它们,而不是在可能存在不一致的地方使用文本字符串。
//
//  AppDelegate.swift
//  SplitterSwift3
//
//  Created by VideoLabN on 4/8/18.
//  Copyright © 2018 VideoLabN. All rights reserved.
//

import UIKit
import AWSAuthCore
import AWSMobileClient
import AWSCore


@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
var auth = SPTAuth()
// Add a AWSMobileClient call in application:open url
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {

    // called when user signs into spotify. Session data saved into user defaults, then notification posted to call updateAfterFirstLogin in ViewController.swift. Modeled off recommneded auth flow suggested by Spotify documentation


    if auth.canHandle(auth.redirectURL) {
        auth.handleAuthCallback(withTriggeredAuthURL: url, callback: { (error, session) in


            if error != nil {
                print("error!")
            }
            let userDefaults = UserDefaults.standard
            let sessionData = NSKeyedArchiver.archivedData(withRootObject: session)
            print(sessionData)
            userDefaults.set(sessionData, forKey: "SpotifySession")
            userDefaults.synchronize()
            NotificationCenter.default.post(name: Notification.Name(rawValue: "loginSuccessfull"), object: nil)
        })
        return true
    }

    return false


}

 //Add a AWSMobileClient call in application:didFinishLaunching
func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions:
    [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    return AWSMobileClient.sharedInstance().interceptApplication(
        application, didFinishLaunchingWithOptions:
        launchOptions)
}

}


//
//  ViewController.swift
//  SplitterSwift3
//
//  Created by VideoLabN on 4/8/18.
//  Copyright © 2018 VideoLabN. All rights reserved.
//

import UIKit
import SafariServices
import AVFoundation
import AWSAuthCore
import AWSAuthUI


class ViewController: UIViewController, SPTAudioStreamingPlaybackDelegate, SPTAudioStreamingDelegate  {

// Variables
var auth = SPTAuth.defaultInstance()!
var session:SPTSession!

// Initialzed in either updateAfterFirstLogin: (if first time login) or in viewDidLoad (when there is a check for a session object in User Defaults
var player: SPTAudioStreamingController?
var loginUrl: URL?

// Outlets
@IBOutlet weak var loginSpotify: UIButton!
@IBOutlet weak var loginSplitter: UIButton!
@IBOutlet weak var testLabel: UILabel!

override func viewDidLoad() {
    print("test")
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    self.setup()
    //NotificationCenter.default.addObserver(self, selector: #selector(ViewController.updateAfterFirstLogin, name: NSNotification.Name(rawValue: "loginSuccessfull"), object: nil)
    //self.updateAfterFirstLogin()

}

func setup () {

    // insert redirect your url and client ID below
    let redirectURL = "splitter-app://callback" // put your redirect URL here
    let clientID = "207ce42c908f42e485c540be11720888" // put your client ID here
    auth.redirectURL     = URL(string: redirectURL)
    auth.clientID        = "client id goes here"
    auth.requestedScopes = [SPTAuthStreamingScope, SPTAuthPlaylistReadPrivateScope, SPTAuthPlaylistModifyPublicScope, SPTAuthPlaylistModifyPrivateScope]
    loginUrl = auth.spotifyWebAuthenticationURL()
    //print("test")


}
func initializePlayer(authSession:SPTSession){
    if self.player == nil {
        self.player = SPTAudioStreamingController.sharedInstance()
        self.player!.playbackDelegate = self
        self.player!.delegate = self
        try! player!.start(withClientId: auth.clientID)
        self.player!.login(withAccessToken: authSession.accessToken)
    }
}
@objc func updateAfterFirstLogin ()  {
    loginSpotify.isHidden = true
    let userDefaults = UserDefaults.standard
    if let sessionObj:AnyObject = userDefaults.object(forKey: "SpotifySession") as AnyObject? {
        let sessionDataObj = sessionObj as! Data
        let firstTimeSession = NSKeyedUnarchiver.unarchiveObject(with: sessionDataObj) as! SPTSession
        self.session = firstTimeSession
        initializePlayer(authSession: session)
    }
}







func audioStreamingDidLogin(_ audioStreaming: SPTAudioStreamingController!) {
    // after a user authenticates a session, the SPTAudioStreamingController is then initialized and this method called
    print("logged in")
//        
self.player?.playSpotifyURI("spotify:track:58s6EuEYJdlb0kO7awm3Vp", 
startingWith: 0, startingWithPosition: 0, callback: { (error) in
//            if (error != nil) {
//                print("playing!")
//            }
//
//        })

    }
@IBAction func spotifyButtonPressed(_ sender: Any) {
    let svc = SFSafariViewController(url: loginUrl!)
    self.present(svc, animated: true, completion: nil)
    //UIApplication.shared.open(loginUrl!, options: [:])


}

}
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {

    if auth.canHandle(auth.redirectURL) {
        auth.handleAuthCallback(withTriggeredAuthURL: url, callback: { (error, session) in
            if error != nil {
                print("error!")
            }
            let userDefaults = UserDefaults.standard
            let sessionData = NSKeyedArchiver.archivedData(withRootObject: session)
            print(sessionData)
            userDefaults.set(sessionData, forKey: "SpotifySession")
            NotificationCenter.default.post(name: Notification.Name(rawValue: "loginSuccessfull"), object: nil)
        })
        return true
    }
    return false  
}