2016-06-25 57 views
2

我試圖讓我的遠程推送通知在我的手機上工作。當我將手機連接到我的電腦並通過手機運行模擬器時,從Firebase控制檯發送的通知完美無缺。但是,當我將其上傳到Testflight並將其下載到我的手機上時,我的推送通知未通過。Firebase推送通知不適用於手機,但可用於模擬器

我的證書是正確上傳及以下是我的代碼

class AppDelegate: UIResponder, UIApplicationDelegate { 

    var window: UIWindow? 

    override init() { 
     FIRApp.configure() 
     FIRDatabase.database().persistenceEnabled = true 
    } 

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
     // Override point for customization after application launch. 
     let notificationTypes : UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound] 
     let notificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil) 
     application.registerForRemoteNotifications() 
     application.registerUserNotificationSettings(notificationSettings) 

     return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions) 
    } 

    func application(application: UIApplication, 
     openURL url: NSURL, 
     sourceApplication: String?, 
     annotation: AnyObject) -> Bool { 
      return FBSDKApplicationDelegate.sharedInstance().application(
       application, 
       openURL: url, 
       sourceApplication: sourceApplication, 
       annotation: annotation) 
    } 

    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. 
     FBSDKAppEvents.activateApp() 
    } 

    func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], 
        fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) { 
     // If you are receiving a notification message while your app is in the background, 
     // this callback will not be fired till the user taps on the notification launching the application. 
     // TODO: Handle data of notification 

     // Print message ID. 
     print("Message ID: \(userInfo["gcm.message_id"]!)") 

     // Print full message. 
     print("%@", userInfo) 

     completionHandler(.NoData) 
    } 


    func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) { 
     print(error) 
     print(error.description) 
    } 
} 

enter image description here

+0

您能否使用生產證書測試推送通知?我有同樣的問題。 Ad-hoc構建不會收到來自Firebase的推送通知。 – sleepwalkerfx

+0

順便說一句,你的屏幕截圖只顯示開發證書。您是否創建了生產SSL證書? – sleepwalkerfx

回答

1

你創建的APN分配證書,並提交到火力地堡控制檯?

請查閱本指南: https://firebase.google.com/docs/cloud-messaging/ios/certs#configure_an_app_id_for_push_notifications

「該應用現已能夠使用推送通知開發環境,當你準備發佈你的應用程序,您需要啓用該應用使用推送通知生產環境:重複這些步驟,但單擊生產SSL證書部分下的創建證書,而不是開發SSL證書。 如果您正在調用setAPNSToken,請確保正確設置type的值:FIRInstanceIDAPNSTokenTypeSandbox用於沙箱環境,或FIRInstanceIDAPNSTokenTypeProd for生產環境如果你沒有設置正確的類型,消息將不會被刪除提供給你的應用程序。「

+0

我確信我擁有它:/ - 我編輯了我的原始帖子以包含圖像 – Tim

0

有沒有更新?

我在其他論壇找到了這個解決方案。如果您使用的火力地堡,你必須添加在:

隨着FirebaseAppDelegateProxyEnabled: NO

TestFlight:

-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { 
[[FIRInstanceID instanceID] setAPNSToken:deviceToken type:FIRInstanceIDAPNSTokenTypeSandbox]; 
} 

生產:

-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { 
[[FIRInstanceID instanceID] setAPNSToken:deviceToken type:FIRInstanceIDAPNSTokenTypeProd]; 
} 

隨着FirebaseAppDelegateProxyEnabled: YES ...理論上這是沒有必要的..

相關問題