0

我正在使用Firebase云消息传递向我发送iOS应用程序中的推送通知。我正在收听我的AppDelegate中的kFIRInstanceIDTokenRefreshNotification通知。一旦应用程序委托获取application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData)中的设备令牌,我的选择器方法kFIRInstanceIDTokenRefreshNotification即被调用。Firebase云消息传递未获得第二次注册

我的问题是,一旦用户注销并再次登录,但是这次在application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData)中接收到设备令牌后,我的选择器方法kFIRInstanceIDTokenRefreshNotification未被调用。

作为观察点,选择器方法在第一次被调用后(即使用户没有注销)不会被调用。

我在下面附上我需要的代码。让我知道是否有其他代码部分是必要的。请有人可以解释我在这里出错的地方。

class AppDelegate: UIResponder { 
     func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
     NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(tokenRefreshNotification(_:)), name: kFIRInstanceIDTokenRefreshNotification, object: nil) 
     return true 
     } 

     func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { 
      FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.Unknown) 
     } 

     func tokenRefreshNotification(notification: NSNotification) { 
      print("Called only first time") 
     } 

    func loginFirebaseWithFacebookAccessToken(accessToken: String) { 
      let credential = FIRFacebookAuthProvider.credentialWithAccessToken(accessToken) 
      if let user = FIRAuth.auth()?.currentUser { 
       user.linkWithCredential(credential) { (user, error) in 
        print("Sign in done") 
       } 
      } else { 
       FIRAuth.auth()?.signInWithCredential(credential) { (user, error) in 
        print("Sign in done") 
       } 
      } 
    } 

    func signOutFromFirebase() { 
     do { 
      try FIRAuth.auth()?.signOut() 
     } 
     catch { 
     } 
    } 
} 
+0

嗨,普拉萨德,我也面临同样的问题,它是否适合你的工作机会吗? – Maheep

+0

@Maheep,我还没有得到任何解决方案。 – Prasad

回答

0

您是否尝试强制退出? 试试吧! FIRAUTH.auth()!signOut()

+0

是的。这是没用的。 – Prasad

+0

我应该在哪里使用这段代码? – Maheep

1

其实我想这行,对我的作品: -

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 

    [[FIRInstanceID instanceID] deleteIDWithHandler:^(NSError * _Nullable error) { 
     // Add observer for InstanceID token refresh callback. 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tokenRefreshNotification:) name:kFIRInstanceIDTokenRefreshNotification object:nil]; 
    }]; 
    return true; 
} 
相关问题