前提・実現したいこと
こんにちは。
作成しているアプリケーションに、保存や保存データの取得を目的にGoogleドライブAPIを利用したいと考えています。しかし、
iOS Quickstart通りにしているつもりなのですが動作してくれません。
コードはビルドできるのですが、Sign Inボタンを押したところで
SIGABRTエラーがでてしまいます。
vi Podfileの内容は以下の通りです。
該当のソースコード
iOS Quickstart通りのものとなります。
手順としては、
pod init→pod Install→open testD.xcworkspace→
へplistを挿入→infoのURL TypesへREVERSED_CLIENT_IDをかきこむ→Clean+Builed→ソースコードを書き込む↓
■AppDelegate
Swift
1 2import GoogleSignIn 3import UIKit 4 5@UIApplicationMain 6class AppDelegate: UIResponder, UIApplicationDelegate { 7 8 var window: UIWindow? 9 10 func applicationDidFinishLaunching(_ application: UIApplication) { 11 // Initialize Google sign-in. 12 GIDSignIn.sharedInstance().clientID = "<CLIENT_IDをいれている>" 13 } 14 15 func application(_ application: UIApplication, 16 open url: URL, sourceApplication: String?, annotation: Any) -> Bool { 17 return GIDSignIn.sharedInstance().handle(url, 18 sourceApplication: sourceApplication, 19 annotation: annotation) 20 } 21 22 @available(iOS 9.0, *) 23 func application(_ app: UIApplication, open url: URL, 24 options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool { 25 let sourceApplication = options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String 26 let annotation = options[UIApplicationOpenURLOptionsKey.annotation] 27 return GIDSignIn.sharedInstance().handle(url, 28 sourceApplication: sourceApplication, 29 annotation: annotation) 30 } 31 32} 33
■ViewCOntroller
Swift
1import GoogleAPIClientForREST 2import GoogleSignIn 3import UIKit 4 5class ViewController: UIViewController, GIDSignInDelegate, GIDSignInUIDelegate { 6 7 8 // If modifying these scopes, delete your previously saved credentials by 9 // resetting the iOS simulator or uninstall the app. 10 private let scopes = [kGTLRAuthScopeDriveReadonly] 11 12 private let service = GTLRDriveService() 13 let signInButton = GIDSignInButton() 14 let output = UITextView() 15 16 override func viewDidLoad() { 17 super.viewDidLoad() 18 print("hoge1") 19 20 // Configure Google Sign-in. 21 GIDSignIn.sharedInstance().delegate = self 22 GIDSignIn.sharedInstance().uiDelegate = self 23 GIDSignIn.sharedInstance().scopes = scopes 24 GIDSignIn.sharedInstance().signInSilently() 25 26 // Add the sign-in button. 27 view.addSubview(signInButton) 28 29 // Add a UITextView to display output. 30 output.frame = view.bounds 31 output.isEditable = false 32 output.contentInset = UIEdgeInsets(top: 20, left: 0, bottom: 20, right: 0) 33 output.autoresizingMask = [.flexibleHeight, .flexibleWidth] 34 output.isHidden = true 35 view.addSubview(output); 36 print("hoge2") 37 } 38 39 func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, 40 withError error: Error!) { 41 if let error = error { 42 print("hoge3") 43 showAlert(title: "Authentication Error", message: error.localizedDescription) 44 self.service.authorizer = nil 45 } else { 46 print("hoge4") 47 self.signInButton.isHidden = true 48 self.output.isHidden = false 49 self.service.authorizer = user.authentication.fetcherAuthorizer() 50 listFiles() 51 } 52 } 53 54 // List up to 10 files in Drive 55 func listFiles() { 56 print("hoge5") 57 let query = GTLRDriveQuery_FilesList.query() 58 query.pageSize = 10 59 service.executeQuery(query, 60 delegate: self, 61 didFinish: #selector(displayResultWithTicket(ticket:finishedWithObject:error:)) 62 ) 63 } 64 65 // Process the response and display output 66 @objc func displayResultWithTicket(ticket: GTLRServiceTicket, 67 finishedWithObject result : GTLRDrive_FileList, 68 error : NSError?) { 69 print("hoge6") 70 if let error = error { 71 showAlert(title: "Error", message: error.localizedDescription) 72 print("hoge7") 73 return 74 } 75 76 var text = ""; 77 if let files = result.files, !files.isEmpty { 78 text += "Files:\n" 79 for file in files { 80 print("hoge8") 81 text += "(file.name!) ((file.identifier!))\n" 82 } 83 } else { 84 print("hoge9") 85 text += "No files found." 86 } 87 output.text = text 88 } 89 90 91 // Helper for showing an alert 92 func showAlert(title : String, message: String) { 93 let alert = UIAlertController( 94 title: title, 95 message: message, 96 preferredStyle: UIAlertControllerStyle.alert 97 ) 98 let ok = UIAlertAction( 99 title: "OK", 100 style: UIAlertActionStyle.default, 101 handler: nil 102 ) 103 alert.addAction(ok) 104 present(alert, animated: true, completion: nil) 105 } 106} 107 108
試したこと
Printしてどこに異常があるのか確かめたところ、ボタンを押した後にViewControllerのif let error = errorの部分で、showAlert()に飛ばされていることはわかりました。
それからSIGABRTエラーになってしまいます。
ほんとうにどこが悪いのかがわからず困っています。
CocoaPodを使用したのもはじめてですので、Podfileの画像もあげさせていただきました。
ひとつきになるのは、pod initの際にiOS Quickstartではplatform8.0と記載してありましたが、サンプルコードでは9.0となっていたので、上記画像のままで実行しています。もしかするとそれが通らない理由なのでしょうか?
現在のバージョンでGoogleAPIを利用しているかたがおられましたら、参考にされたサイトや方法をお教え願えないでしょうか。
初学者の質問となり、申し訳ありませんがよろしくおねがいいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/06/06 00:05
2018/06/07 05:40
2018/06/07 09:37
2018/06/09 01:16
2018/06/10 05:31