2016-11-11 8 views
1

私はObjective CのiOSアプリケーションでFirebaseにいくつかの問題があります。Firebaseヘルプ - 複数のデータベース

このアプリケーションでは、カスタムログインデータベースとしてFirebaseが使用されています。

アプリはもともとユーザー名とパスワードを含むfirebaseデータベースに接続していました。

私は以来、firebaseへの別の接続を導入し、リアルタイムでデータをtableViewに取得しています。これは別の火災基地プロジェクトにあります。 1つのプロジェクトの一部として両方のデータベースを持つ方法がわかりません。

私はGoogleService-Info.plistを追加しましたが、1つのDATABASE_URLのみが許可されています。複数のDATABASE_URLを持つことは可能ですか?私は必要に応じてプロジェクトを切り替えたいと思っています。

ログインのコードは、firebaseバージョン1.0に基づいています。アプリはfirebaseに 'webservice'のURLで接続されています。

私はFirebaseの最新リリースに更新されており、コードは現在壊れています。非難された参照の一部を更新し、ほとんどのエラーをクリアしました。

私はアプリを実行してログインしようとするとエラーが発生します。ログインのためのfirebaseプロジェクトのURLへの接続はありません。

下記のログイン機能のコードを追加します。

- (IBAction)login:(id)sender 
{ 
    if (txtEmail.text.length > 0 && txtToken.text.length > 0) { 
     if ([sharedHelper isConnectedToInternet]) { 
      [self.activityView startAnimating]; 

      //If the user has purchased but not logged in, when they do login we want to add their purchases to their user 
      NSUserDefaults *settings = [NSUserDefaults standardUserDefaults]; 

      [settings setObject:txtEmail.text forKey:@"userEmail"]; 
      [settings setObject:txtToken.text forKey:@"userToken"]; 

      NSMutableDictionary *purchase = [settings objectForKey:@"UnRecordedPurchase"]; 
      NSString *subscriptionLength = @"0"; 
      NSString *expiryDate = @""; 
      NSString *receiptData = @""; 
      if (purchase) 
      { 
       subscriptionLength = [purchase objectForKey:@"subscriptionLength"]; 
       expiryDate = [purchase objectForKey:@"expiryDate"]; 
       receiptData = [purchase objectForKey:@"receiptData"]; 
      } 
      [settings setObject:nil forKey:@"UnRecordedPurchase"]; 
      [settings synchronize]; 

      //Firebase *firebase = [[Firebase alloc] initWithUrl:kLOGINWEBSERVICEURL]; 
      FIRDatabaseReference *firebase= [[FIRDatabase database] reference]; 

      [firebase observeSingleEventOfType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) { 
       [self.activityView stopAnimating]; 

       if (snapshot.value == [NSNull null]) { 
        // No data found 
        NSString *errorMessage = @"Unable to check login details - please contact [email protected]"; 
        [self showStatusMessage:errorMessage]; 

       } else { 
        NSMutableArray *matchingEmailChildren = [[NSMutableArray alloc] initWithCapacity:0]; 

        for (FIRDataSnapshot *child in snapshot.children) { 
         NSDictionary *dict = child.value; 

         // Check the email address 

         if ([[[dict valueForKey:@"Email"] lowercaseString] isEqualToString:[self.txtEmail.text lowercaseString]]) { 
          [matchingEmailChildren addObject:child]; 
         } 
        } 

        if ([matchingEmailChildren count] > 0) { 
         NSMutableArray *matchingTokenChildren = [[NSMutableArray alloc] initWithCapacity:0]; 

         // Check for matching token 
         for (FIRDataSnapshot *child in matchingEmailChildren) { 
          NSDictionary *dict = child.value; 

          if ([[[dict valueForKey:@"Token"] lowercaseString] isEqualToString:[self.txtToken.text lowercaseString]]) { 

           [matchingTokenChildren addObject:child]; 
          } 
         } 

         if ([matchingTokenChildren count] > 0) { 
          BOOL loginSuccess = NO; 

          // Check expiry date 
          for (FIRDataSnapshot *child in matchingTokenChildren) { 
           NSDictionary *dict = child.value; 

           // Get today's date, just as the date without time values 
           NSCalendar *calendar = [NSCalendar currentCalendar]; 
           NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay 
                      fromDate:[NSDate date]]; 
           [components setHour:12]; 
           [components setMinute:0]; 
           [components setSecond:0]; 

           NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
           [dateFormatter setDateFormat:@"dd/MM/yyyy"]; 

           NSDate *todaysDate = [calendar dateFromComponents:components]; 

           // Format expiry date to just the date component 

           components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay 
                 fromDate:[dateFormatter dateFromString:[dict valueForKey:@"ExpiryDate"]]]; 

           [components setHour:12]; 
           [components setMinute:0]; 
           [components setSecond:0]; 

           NSDate *expiryDate = [calendar dateFromComponents:components]; 

           if ([expiryDate compare:todaysDate] == NSOrderedSame || [expiryDate compare:todaysDate] == NSOrderedDescending) { 

            NSMutableDictionary *userDict = [[NSMutableDictionary alloc] init]; 
            [userDict setObject:self.txtEmail.text forKey:@"Username"]; 
            [userDict setObject:self.txtToken.text forKey:@"Token"]; 

            // Change format of expiry date for compatibility purposes and convert to string to save locally 
            NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
            [dateFormatter setDateFormat:@"yyyyMMdd"]; 
            NSString *expiryDateAsString = [dateFormatter stringFromDate:expiryDate]; 

            [userDict setObject:expiryDateAsString forKey:@"ExpiryDate"]; 

            [sharedHelper addUserWithDictionary:userDict fromCloud:NO]; 

            [self loginSuccess]; 

            loginSuccess = YES; 

            break; 
           } 
          } 

          if (loginSuccess == NO) { 
           NSString *errorMessage = @"Your Annual Subscription has expired. Contact [email protected]"; 
           [self showStatusMessage:errorMessage]; 
          } 

         } else { 
          NSString *errorMessage = @"Your Code is incorrect for this email address."; 
          [self showStatusMessage:errorMessage]; 

          [self.txtToken becomeFirstResponder]; 
         } 

        } else { 
         NSString *errorMessage = @"We cannot find your email address on our system.\r\n\r\n For assistance contact [email protected]"; 
         [self showStatusMessage:errorMessage]; 

         [self.txtEmail becomeFirstResponder]; 
        } 
       } 

      } withCancelBlock:^(NSError *error) { 
       NSString *errorMessage = @"Unable to check login details - please contact [email protected]"; 
       [self showStatusMessage:errorMessage]; 
      }]; 

     } else { 
      NSString *errorMessage = @"Unable to validate email & code details. Please check your internet connection."; 
      [self showStatusMessage:errorMessage]; 
     } 
    } else { 
     NSString *errorMessage = @"Please enter email address and code."; 
     [self showStatusMessage:errorMessage]; 
    } 
} 

上記のコードに誤りがありましたら教えてください。

おかげ WG

答えて

0

一つだけの余分なデータベースを必要とする場合は、Firebase認証になっているはずです。電子メールとパスワード、Google、Facebook、Twitter、GitHubなどのプロバイダでサインインできます。次に、1つのデータベースURLとFirebase Authへの参照が必要になります。

関連する問題