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

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

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

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

Swift

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

Q&A

解決済

1回答

709閲覧

iosアプリでFirebaseのpush(FCM)部分でリジェクトされる問題が解決出来ません。

po_tato

総合スコア97

iOS

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

Swift

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

0グッド

0クリップ

投稿2018/04/04 02:27

iosアプリにFirebaseのpushサービスを実装しています。

pushは自サーバーにユーザー情報を登録してpush通知を送信するという方法をとっています。
動作は何の問題もなく正常なのですが、これを実装したアプリを審査に提出すると決まって同じ部分でクラッシュしているらしくリジェクトされます。ログを見ると、"tokenRefreshNotification"とあるので、push部分でクラッシュしているんだろうなということは分かるのですが、如何せんこちらでは何の問題もなく、クラッシュを再現することが出来ず一ヶ月くらい途方に暮れています。

何かFCMのpushを実装する上で、抜けている部分(エラー処理など)があるのでしょうか?
私と同じようにFCMを実装している方で問題なく審査に通過している方や、ソースを見て
おかしい部分があると思う方にご意見をいただきたいです。
AppDelegateとクラッシュログを添付しています。
クラッシュログはアプリ名を"MyApp"に変更させて頂いています。

AppDelegate

// AppDelegate.swift import UIKit import Firebase import UserNotifications import FirebaseInstanceID import FirebaseMessaging @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate{ var message0:String? var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. // [START register_for_notifications] if #available(iOS 10.0, *) { let authOptions : UNAuthorizationOptions = [.alert, .badge, .sound] UNUserNotificationCenter.current().requestAuthorization( options: authOptions, completionHandler: {_,_ in }) // For iOS 10 display notification (sent via APNS) UNUserNotificationCenter.current().delegate = self // For iOS 10 data message (sent via FCM) FIRMessaging.messaging().remoteMessageDelegate = self } else { let settings: UIUserNotificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil) application.registerUserNotificationSettings(settings) } application.registerForRemoteNotifications() FIRApp.configure() // Add observer for InstanceID token refresh callback. NotificationCenter.default.addObserver(self, selector: #selector(self.tokenRefreshNotification), name: .firInstanceIDTokenRefresh, object: nil) return true } private func application(application: UIApplication, didReceiveRemoteNotification userInfo: [String : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) { // Print message ID. print("Message ID: )",userInfo["gcm.message_id"]!) // Print full message. print("%@", userInfo) // UIAlertController let alertController: UIAlertController = UIAlertController(title: "Alert", message: "Test UIAlertController", preferredStyle: .alert) let actionOK = UIAlertAction(title: "OK", style: .default){ action in } let actionCancel = UIAlertAction(title: "Cancel", style: .cancel){ (action) -> Void in } // actionを追加 alertController.addAction(actionOK) alertController.addAction(actionCancel) // UIAlertの起動 self.window?.rootViewController?.present(alertController, animated: true, completion: nil) } // [START refresh_token] func tokenRefreshNotification(_ notification: Notification) { if let refreshedToken = FIRInstanceID.instanceID().token() { print("InstanceID token: (refreshedToken)") let ud = UserDefaults.standard let id = ud.string(forKey: "id") let pass = ud.string(forKey: "pass") let param = "id="+id!+"&passwd="+pass! /** プッシュ登録 */ let token = FIRInstanceID.instanceID().token() let param_push = param+"&devicetoken="+token! let test_push = BG_home(url_dom: "http://test/testApi/test.php", url_param: param_push) test_push.get(){json in print("test: (json)") } } // Connect to FCM since connection may have failed when attempted before having a token. connectToFcm() } //FCMサーバーに接続 func connectToFcm() { FIRMessaging.messaging().connect { (error) in if (error != nil) { print("Unable to connect with FCM. (error!)") } else { print("Connected to FCM." ,error as Any) UIApplication.shared.applicationIconBadgeNumber = 0 } } } func applicationWillResignActive(_ application: UIApplication) { } func applicationDidEnterBackground(_ application: UIApplication) { FIRMessaging.messaging().disconnect() print("Disconnected from FCM.") } func applicationWillEnterForeground(_ application: UIApplication) { } func applicationDidBecomeActive(_ application: UIApplication) { connectToFcm() } func applicationWillTerminate(_ application: UIApplication) { } } @available(iOS 10, *) extension AppDelegate : UNUserNotificationCenterDelegate { // Receive displayed notifications for iOS 10 devices. func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { let userInfo = notification.request.content.userInfo print("%@", userInfo) let aps = userInfo["aps"]! as! Dictionary<String,AnyObject> let aps2 = aps["alert"]! as! Dictionary<String,AnyObject> let push_title = aps2["title"] as! String let push_body = aps2["body"] as! String // UIAlertController let alertController: UIAlertController = UIAlertController(title: push_title, message: push_body, preferredStyle: .alert) // 選択肢 // 異なる方法でactionを設定してみた let actionOK = UIAlertAction(title: "OK", style: .default){ action in UIApplication.shared.applicationIconBadgeNumber = 0 } // actionを追加 alertController.addAction(actionOK) // UIAlertの起動 self.window?.rootViewController?.present(alertController, animated: true, completion: nil) } } extension AppDelegate : FIRMessagingDelegate { // Receive data message on iOS 10 devices. func applicationReceivedRemoteMessage(_ remoteMessage: FIRMessagingRemoteMessage) { print("%@", remoteMessage.appData) } }

crashlog

{"app_name":"Myapp","timestamp":"2018-04-04 03:10:04.08 +0900","app_version":"1.41","slice_uuid":"d61d1c7e-b94a-3301-8e27-eeef3fcb4db5","adam_id":1168856662,"build_version":"41","bundleID":"com.Myapp","share_with_app_devs":false,"is_first_party":false,"bug_type":"109","os_version":"iPhone OS 11.3 (15E216)","incident_id":"842B54E9-060F-42FF-9638-E0505DE53D5C","name":"Myapp"} Incident Identifier: 842B54E9-060F-42FF-9638-E0505DE53D5C CrashReporter Key: 9cab8f54502e04c78114cd75c6340dbd1210669b Hardware Model: xxx Process: Myapp [268] Path: /private/var/containers/Bundle/Application/7FC306BF-F35D-4D41-B865-D129409CC6B1/Myapp.app/Myapp Identifier: com.Myapp Version: 20 (1.41) Code Type: ARM-64 (Native) Role: Foreground Parent Process: launchd [1] Coalition: com.Myapp [433] Date/Time: 2018-04-04 03:10:03.9596 +0900 Launch Time: 2018-04-04 03:09:56.2755 +0900 OS Version: iPhone OS 11.3 (15E216) Baseband Version: 4.56.00 Report Version: 104 Exception Type: EXC_BREAKPOINT (SIGTRAP) Exception Codes: 0x0000000000000001, 0x0000000104ce9490 Termination Signal: Trace/BPT trap: 5 Termination Reason: Namespace SIGNAL, Code 0x5 Terminating Process: exc handler [0] Triggered by Thread: 0 Filtered syslog: None found Thread 0 name: Dispatch queue: com.apple.main-thread Thread 0 Crashed: 0 Myapp 0x0000000104ce9490 specialized AppDelegate.tokenRefreshNotification(_:) + 185488 (AppDelegate.swift:121) 1 Myapp 0x0000000104ce7120 @objc AppDelegate.tokenRefreshNotification(_:) + 176416 (AppDelegate.swift:0) 2 CoreFoundation 0x0000000185680c3c 0x1855a9000 + 883772 3 CoreFoundation 0x00000001856801b8 0x1855a9000 + 881080 4 CoreFoundation 0x000000018567ff14 0x1855a9000 + 880404 5 CoreFoundation 0x00000001856fd84c 0x1855a9000 + 1394764 6 CoreFoundation 0x00000001855b6f38 0x1855a9000 + 57144 7 Foundation 0x000000018609c8c8 0x186021000 + 506056 8 CoreFoundation 0x0000000185696910 0x1855a9000 + 973072 9 CoreFoundation 0x0000000185694238 0x1855a9000 + 963128 10 CoreFoundation 0x0000000185694768 0x1855a9000 + 964456 11 CoreFoundation 0x00000001855b4da8 0x1855a9000 + 48552 12 GraphicsServices 0x0000000187597020 0x18758c000 + 45088 13 UIKit 0x000000018f59578c 0x18f278000 + 3266444 14 Myapp 0x0000000104cc7d5c main + 48476 (AppDelegate.swift:14) 15 libdyld.dylib 0x0000000185045fc0 0x185045000 + 4032 Thread 1: 0 libsystem_kernel.dylib 0x0000000185175d84 0x185153000 + 142724 1 libsystem_pthread.dylib 0x0000000185313eb4 0x185313000 + 3764 2 libsystem_pthread.dylib 0x0000000185313b08 0x185313000 + 2824

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

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

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

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

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

guest

回答1

0

ベストアンサー

AppDelegateのtokenRefreshNotificationメソッド内(121行目)で
落ちているようですが、それはどの行ですか?

もし

swift

1let param = "id="+id!+"&passwd="+pass!

だったら、idやpassがnilだったということではないでしょうか?

idやpassは、初めてアプリを起動したタイミングでは
まだ保存されていないということはないですか?

投稿2018/04/04 04:29

編集2018/04/04 15:48
TakeOne

総合スコア6299

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

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

po_tato

2018/04/04 06:11 編集

appdelegateのコメントアウトで記載していたのですが、分かりづらかったですね。すみません。おっしゃる通り121行目はその部分を示しています。クラッシュ理由もSIGTRAPですし、nilが入っているのかもしれないなと予想していたのですが、やはりそうでしょうか?一番最初に表示されるviewControllerでidやpassを設定しているのですが、それよりも早くこちらのコードが走ってしまって結果nilになっているということなんでしょうか・・ let param = "id="+id!+"&passwd"+pass! の上の行に、 if(id != nil && pass != nil) このif文を追加するのはおかしいでしょうか?
TakeOne

2018/04/05 02:37 編集

> if(id != nil && pass != nil) このif文を追加するのはおかしいでしょうか? それを入れることで今回のエラーは回避できると思います。 (問題の処理を単純にif文でスキップして、別のところで問題が出るかどうかは知りません。) シミュレータや実機から自分のアプリを一旦削除してから実行したら、 UserDefaultsから取得したidもpassもnilになり、 クラッシュが再現できるんじゃないでしょうか?
po_tato

2018/04/05 00:48

それが、何度試しても(TestFlightなどでもやっているんですが)クラッシュしないんですよね。しっかりとアプリは削除してやっているんですが、、、だけど、審査員の方ではそうなっているっぽいですね。とりあえず、上記記載した"if(id != nil && pass != nil)"追加して提出してみたいと思います。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問