DropboxAPIをSwiftから使おうと思っています。
https://qiita.com/keonheon/items/b08a63552d2cd46cb477
上のサイトを参考にコードを書いて実行してみました。
書き込んだコードは下の通りです。
AppDelegate.swift import UIKit import SwiftyDropbox @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? private func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { DropboxClientsManager.setupWithAppKey("wj3flf4046e0ana") // Override point for customization after application launch. return true } private func application(_ app: UIApplication, openURL url: URL,options: [String : AnyObject]) -> Bool{ if let authResult = DropboxClientsManager.handleRedirectURL(url) { switch authResult{ case .success(let token): print("Success! User is logged into Dropbox with token: (token)") case .error(let error, let description): print("Error(error):(description)") case .cancel: print("Authorization flow was manually canceled by user!") } } return false } func applicationWillResignActive(_ application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. } func applicationDidEnterBackground(_ application: UIApplication) { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } func applicationWillEnterForeground(_ application: UIApplication) { // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. } func applicationDidBecomeActive(_ application: UIApplication) { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } func applicationWillTerminate(_ application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. // Saves changes in the application's managed object context before the application terminates. } // MARK: - Core Data stack }
ViewController.swift import UIKit import SwiftyDropbox class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. let signInButton = UIButton(type: UIButtonType.system) signInButton.frame = CGRect(x:10, y:30, width:100, height:30) signInButton.setTitle("Sign In", for: .normal) signInButton.addTarget(self, action: Selector(("signInDropbox")), for: .touchUpInside) self.view.addSubview(signInButton) } func signInDropbox(){ if let _ = DropboxClientsManager.authorizedClient{ DropboxClientsManager.unlinkClients() } DropboxClientsManager.authorizeFromController(UIApplication.shared, controller: self, openURL: {(url: URL) -> Void in UIApplication.shared.openURL(url)}) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }
実行はできたのですが、サインインしようとしたらエラーで、AppDelegate.swiftの上から4行目、「 class AppDelegate: UIResponder, UIApplicationDelegate { 」のところが赤線で引かれ、「 Thread 1: signal SIGABRT 」と表示され、アプリケーションが停止してしまいます。
どうすればこのエラーが表示されなくなるかわかりません。
どなたか分かる方いらっしゃいましたら、回答よろしくお願いします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/01/11 11:33 編集
2018/01/12 05:19
2018/12/26 11:51
2018/12/26 12:37