質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

解決済

2回答

398閲覧

XcodeでSwiftyDropboxにサインインできない

Laz0530

総合スコア15

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

0クリップ

投稿2018/01/10 10:00

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 」と表示され、アプリケーションが停止してしまいます。

どうすればこのエラーが表示されなくなるかわかりません。
どなたか分かる方いらっしゃいましたら、回答よろしくお願いします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

ベストアンサー

テスト環境

  • MacOS Sierra 10.12.6
  • Xcode 9.2 Build version 9C40b
  • Apple Swift version 4.0.3 (swiftlang-900.0.74.1 clang-900.0.39.2)

下はともかく、上のprivateはビルド通るんかね。
Sign Inボタンを押下し、Dropboxのログイン画面が出るところまでの正常動作を確認しました。

swift

1 override func viewDidLoad() { 2 super.viewDidLoad() 3 // Do any additional setup after loading the view, typically from a nib. 4 5 let signInButton = UIButton(type: UIButtonType.system) 6 signInButton.frame = CGRect(x:10, y:30, 7 width:100, height:30) 8 signInButton.setTitle("Sign In", for: .normal) 9// signInButton.addTarget(self, action: Selector(("signInDropbox")), for: .touchUpInside) 10 signInButton.addTarget(self, action: #selector(self.signInDropbox), for: .touchUpInside) 11 self.view.addSubview(signInButton) 12 13 } 14 15// func signInDropbox(){ 16 @objc func signInDropbox(){ 17 if let _ = DropboxClientsManager.authorizedClient{ 18 DropboxClientsManager.unlinkClients() 19 } 20 DropboxClientsManager.authorizeFromController(UIApplication.shared, controller: self, openURL: {(url: URL) -> Void in UIApplication.shared.openURL(url)}) 21 }
<key>LSApplicationQueriesSchemes</key> <array> <string>dbapi-8-emm</string> <string>dbapi-2</string> </array>

参考

GitHub - dropbox/SwiftyDropbox: Swift SDK for the Dropbox API v2.

追記

大変失礼しました。AppDelegate.swiftの修正を記載していませんでした。
参考にしているページはネタが古いので、公式の方を見ながら進めていってください。

swift

1// private func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 2// 3// DropboxClientsManager.setupWithAppKey("wj3flf4046e0ana") 4// // Override point for customization after application launch. 5// return true 6// } 7 8 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 9 // Override point for customization after application launch. 10 11 DropboxClientsManager.setupWithAppKey("wj3flf4046e0ana") 12 13 return true 14 }

投稿2018/01/10 22:37

編集2018/01/11 21:53
izkn

総合スコア1698

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Laz0530

2018/01/11 11:33 編集

すみません、教えていただいたコードに書き直して実行して見ましたが、また異なるエラーが出てしまいました。 OAuthMobile.swift内のコード、precondition(DropboxOAuthManager.sharedOAuthManager != nil, "Call `DropboxClientsManager.setupWithAppKey` or `DropboxClientsManager.setupWithTeamAppKey` before calling this method") に線が引かれ、 Thread 1: Precondition failed: Call `DropboxClientsManager.setupWithAppKey` or `DropboxClientsManager.setupWithTeamAppKey` before calling this method との注意書きが表示されました。この現象について何かご存知であれば再度お教えいただけないでしょうか? よろしくお願いします。
Laz0530

2018/01/12 05:19

追記ありがとうございます。 無事動きました!! 丁寧に説明していただき、とても分かり易かったです^^ 本当にありがとうございました!
DrqYuto

2018/12/26 11:51

@objc func signInDropbox(){ if let _ = DropboxClientsManager.authorizedClient{ DropboxClientsManager.unlinkClients() } DropboxClientsManager.authorizeFromController(UIApplication.shared, controller: self, openURL: {(url: URL) -> Void in UIApplication.shared.openURL(url)}) } でUse of unresolved identifier 'DropboxClientsManager' のエラーになってしまいました
DrqYuto

2018/12/26 12:37

import SwiftyDropbox忘れていました…つけたらできました。
guest

0

privateがついてるのは変かも。とってみてください。

swift

1 //private func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 2 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 3 4 //private func application(_ app: UIApplication, openURL url: URL,options: [String : AnyObject]) -> Bool{ 5 func application(_ app: UIApplication, openURL url: URL,options: [String : AnyObject]) -> Bool{ 6

例外がスローされてれば問題箇所が掴めるので、Xcodeで、Exception Breakpointsを設定してみてください。「Xcode 例外」でググれば設定の仕方が出てきます。

投稿2018/01/10 10:16

fromageblanc

総合スコア2724

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Laz0530

2018/01/11 11:35

回答ありがとうございます。お教えいただいた通りWxception Breakpointsを設定してみましたが、エラーの場所を把握できませんでした。。。 ですが、貴重な情報、本当にありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問