2016-05-09 8 views
1

:。QuickBloxビデオチャット:QBRequest.logInWithUserEmail対QBChat.instance()connectWithUser私はiOSのチュートリアルに従うことによって構築されたシンプルなQuickBloxチャットアプリを持っている

http://quickblox.com/developers/Sample-webrtc-ios#Sources

が、私は成功し、ユーザーを作成し、ログインしましたしかし、私はセッションを開始しようとするとエラーに遭遇します。「チャットAPIを使用するにはログインする必要があります」

let newSession: QBRTCSession = QBRTCClient.instance().createNewSessionWithOpponents(["12498970"], withConferenceType: QBRTCConferenceType.Video) 

私はそれを開くconnectWithUserたびQBChat.instance()を追加することによってこの問題を解決することができるよ:。

QBChat.instance().connectWithUser(user!) { (error) in 
     if error != nil { 
      print("error: \(error)") 
     } 
     else { 
      print("login to chat succeeded") 
     } 
    } 

しかし、私はパスワードをキャッシュたりするか持っているので、何とかこれは奇妙なようですアプリを開くたびにパスワードを入力するようにユーザーに求めます。 QBSession.currentSession()。currentUserはまだ有効ですが、QBChatユーザーは無効になっているのは奇妙です。これを達成するためのベストプラクティスは何ですか?すべてのサンプルで、パスワードはハードコードされています。これは素晴らしい解決策のようには見えません。

+1

私は考えています今私はログイン状況をかなり取得していません。 SDKのビデオチャットサンプルは、QBChat.instance().connectWithUserのみを使用し、QBRequest.logInWithUserLoginは使用しません。まだそれをやった人からのいくつかの洞察を期待しています。 – mitrenegade

答えて

0

私は基本的に彼らの全体のパッケージを実証し、だけでなく、あなたのチャットのニーズがあるものは何でものために実際のソリューションを提供するために構築されたQuickbloxの人々のアプリですQ-municate、の例を、以下のことになりました。私はいくつかの他のカスタムのものを持っていると私はまだ、彼らはそれを実装する方法の詳細を通じて掘るしようとしているので、多くの機能を必要としません。 Q-municateへのリンク:

http://quickblox.com/developers/Q-municate#1._Get_the_source_code loginWithEmailで

[[QMApi instance] loginWithEmail:email 
          password:password 
          rememberMe:weakSelf.rememberMeSwitch.on 
          completion:^(BOOL success) 
    { 
     [SVProgressHUD dismiss]; 

     if (success) { 
      [[QMApi instance] setAutoLogin:weakSelf.rememberMeSwitch.on 
          withAccountType:QMAccountTypeEmail]; 
      [weakSelf performSegueWithIdentifier:kTabBarSegueIdnetifier 
              sender:nil]; 
     } 
    }]; 

、彼らはSettingsManagerキャッシュこのログイン:

  [weakSelf.settingsManager setLogin:email andPassword:password]; 

実際にだけの方法である彼らのログインフローで

、彼らはQ-municateのために書かれQMApiモジュールを使用しますSSKeyChainにパスワードをキャッシュします。

NSString *password = [SSKeychain passwordForService:kQMAuthServiceKey account:self.login]; 

自動ログインが呼び出される:self.settingsManager.passwordはSSKeychainからパスワードを引っ張る

if (!self.isAuthorized) { 
    if (self.settingsManager.accountType == QMAccountTypeEmail && self.settingsManager.password && self.settingsManager.login) { 

     NSString *email = self.settingsManager.login; 
     NSString *password = self.settingsManager.password; 

     [self loginWithEmail:email password:password rememberMe:YES completion:completion]; 
    } 
    else if (self.settingsManager.accountType == QMAccountTypeFacebook) { 

     [self loginWithFacebook:completion]; 
    } 
    else { 

     if (completion) completion(NO); 
    } 
} 
else { 
    if (completion) completion(YES); 
} 

:あなたがアプリに戻ったときに

[SSKeychain setPassword:password forService:kQMAuthServiceKey account:login]; 

その後、彼らは自動ログインを呼び出しますメインのチャットタブが読み込まれます。それはconnectToChatに私たちの古典的な呼び出しを行う:

[[QMApi instance] autoLogin:^(BOOL success) { 
    if (!success) { 

     [[QMApi instance] logoutWithCompletion:^(BOOL succeed) { 
      // 
      [weakSelf performSegueWithIdentifier:@"SplashSegue" sender:nil]; 
     }]; 

    } else { 

     // subscribe to push notifications 
     [[QMApi instance] subscribeToPushNotificationsForceSettings:NO complete:^(BOOL subscribeToPushNotificationsSuccess) { 

      if (!subscribeToPushNotificationsSuccess) { 
       [QMApi instance].settingsManager.pushNotificationsEnabled = NO; 
      } 
     }]; 

     [weakSelf connectToChat]; 
    } 
}]; 

だから技術的にドキュメントアプリが開いていないとのチャットは、もはや接続されるたびにチャットにログインすることで、正しいことをやっています。ユーザーがそれを再入力する必要はありませんので、そのパスワードを保存するためのはるかに複雑ですが、安全な方法はただあります。

TLDR:それは私のコードで動作する方法(かつ迅速には)次のとおりです。

ログインの場合:

QBRequest.logInWithUserEmail(email, password: password, successBlock: { (response, user) in 
     SSKeychain.setPassword(password, forService: "kMyAppLoginServiceKey", account: email) 

     }) { (errorResponse) in 
      print("Error: \(errorResponse)") 
      self.simpleAlert("Could not log in", defaultMessage: nil, error: nil) 
    } 

たびチャットビューのロード:

if !QBChat.instance().isConnected() { 
     QBRTCClient.initializeRTC() 
     QBRTCClient.instance().addDelegate(self) 

     let user = QBSession.currentSession().currentUser 
     let password = SSKeychain.passwordForService("kMyAppLoginServiceKey", account: user?.email!) 
     user!.password = password 
     QBChat.instance().addDelegate(self) 
     QBChat.instance().connectWithUser(user!) { (error) in 
      if error != nil { 
       print("error: \(error)") 
      } 
      else { 
       print("login to chat succeeded") 
      } 
     } 
    } 
関連する問題