swift3でSiriショートカットでアプリを呼び出せるアプリを作っています。
(NSUserActivityを使用する方法で作っています)
XCODEのバージョンは、10.1 (10B61)です。
なぜか、AppDelegateのapplicationが呼び出せません。また、以下のWariningが表示されます。
xcodeWarning
1Instance method 'application(_:continue:restorationHandler:)' nearly matches optional requirement 'application(_:continue:restorationHandler:)' of protocol 'UIApplicationDelegate'
swift3
1func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
application(_:continue:restorationHandler:)のところで他に関数でマッチする可能性があるということでのワーニングと思いますが、こちらの回避方法がわかりません。
Siriショートカットの以下のサンプルアプリはワーニングも出ませんし実機で正常に動作するのも確認できました。
https://github.com/ali312/SiriShortcutsTutorial
(AppDelegateファイル)
https://github.com/ali312/SiriShortcutsTutorial/blob/master/SiriShortcutsTutorial/AppDelegate.swift
そのため、GoogleやFacebookのサインインが関係していると思っていますが、共存して利用したいので回避策があれば教えて頂きますようよろしくお願いします。
今記載し動作させているAppDelegate.swiftの全文を以下に示します。
以下を動作させてSiriショートカットを利用すると本アプリは起動しますが、AppDelegateのapplication(_:continue:restorationHandler:)が呼び出されません。
また、XCODEの推奨Fixで@nonobjc,privateなども試しましたが、呼び出されませんでした。
逆に、@objc(application:continue:restorationHandler:)と記載しObject-Cで呼び出すように明記しても呼び出されませんでした。
このような場合にどのようにしたら良いかご教授をお願いします。
swift3
1import UIKit 2import Firebase 3import GoogleSignIn 4import FBSDKCoreKit 5import AVFoundation 6 7@UIApplicationMain 8class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate { 9 10 var window: UIWindow? 11 var cloudLoginViewController: cloudLoginViewController! 12 13 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 14 // Forebase 15 FirebaseApp.configure() 16 // Google連携 17 if let gidSignIn = GIDSignIn.sharedInstance() { 18 gidSignIn.clientID = FirebaseApp.app()?.options.clientID 19 gidSignIn.delegate = self as GIDSignInDelegate 20 } 21 // Facebook連携 22 FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions) 23 // バックグラウンドでの音の再生を許可 24 do { 25 let audioSession : AVAudioSession = AVAudioSession.sharedInstance() 26 try audioSession.setCategory(AVAudioSessionCategoryAmbient) 27 } catch { 28 } 29 return true 30 } 31 32 // Siriショートカット 33 func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool { 34 if let parameters = userActivity.userInfo as? [String: Int] { 35 let viewController = window?.rootViewController as! TabMenuViewController 36 let value1 = parameters["curNo"]! as Int 37 viewController.curNo = value1 38 let value2 = parameters["numBtn"]! as Int 39 viewController.irNumBtn = value2 40 viewController.sendIrJob() 41 return true 42 } 43 return false 44 } 45 46 func applicationWillResignActive(_ application: UIApplication) { 47 } 48 49 func applicationDidEnterBackground(_ application: UIApplication) { 50 } 51 52 func applicationWillEnterForeground(_ application: UIApplication) { 53 } 54 55 func applicationDidBecomeActive(_ application: UIApplication) { 56 } 57 58 func applicationWillTerminate(_ application: UIApplication) { 59 } 60 61 @available(iOS 9.0, *) 62 func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool { 63 let sourceApplication = options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String 64 let annotation = options[UIApplicationOpenURLOptionsKey.annotation] 65 66 let googleHandler = GIDSignIn.sharedInstance().handle( 67 url, 68 sourceApplication: sourceApplication, 69 annotation: annotation ) 70 71 let facebookHandler = FBSDKApplicationDelegate.sharedInstance().application ( 72 app, 73 open: url, 74 sourceApplication: sourceApplication, 75 annotation: annotation ) 76 77 return googleHandler || facebookHandler 78 } 79 80 //for iOS 8, check availability 81 @available(iOS, introduced: 8.0, deprecated: 9.0) 82 func application(_ app: UIApplication,open url: URL, sourceApplication: String?, annotation: Any) -> Bool { 83 //return GIDSignIn.sharedInstance().handle(url as URL!, sourceApplication: sourceApplication!, annotation: annotation) 84 let googleHandler = GIDSignIn.sharedInstance().handle( 85 url, 86 sourceApplication: sourceApplication, 87 annotation: annotation ) 88 89 let facebookHandler = FBSDKApplicationDelegate.sharedInstance().application ( 90 app, 91 open: url, 92 sourceApplication: sourceApplication, 93 annotation: annotation ) 94 95 return googleHandler || facebookHandler 96 } 97 98 func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?) { 99 if let error = error { 100 print(error.localizedDescription) 101 return 102 } 103 guard let authentication = user.authentication else { return } 104 let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken, accessToken: authentication.accessToken) 105 106 Auth.auth().signIn(with: credential) { (user, error) in 107 if let error = error { 108 print(error.localizedDescription) 109 return 110 } 111 print("User is signed in") 112 let appDelegate = UIApplication.shared.delegate as! AppDelegate 113 appDelegate.cloudLoginViewController.snsUserReg() 114 } 115 } 116 117 func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!, withError error: Error!) { 118 print("AppDelegate sign didDisconnectWith") 119 } 120}

回答1件
あなたの回答
tips
プレビュー