没有调用iOS setValue withCompletionBlock

时间:2016-10-07 18:16:09

标签: ios objective-c firebase firebase-realtime-database

我在设置值时遇到了一些未在iOS(模拟器和设备)上调用的completionBlocks,例如:

- (void)addShortUserPlaylistUrl:(NSString *)playlistId
                   playlistName:(NSString *)playlistName 
                userDisplayName:(NSString *)userDisplayName 
                completionBlock:(ObjectBlock)completionBlock 

{ 

    FIRDatabaseReference *newUserPlaylistUrlRef = [[_root child:KPLRUserPlaylistUrlRef] childByAutoId]; 

    if (newUserPlaylistUrlRef != nil) { 

        NSString *key = [newUserPlaylistUrlRef key]; 
        NSDictionary *dict = @{ @"playlistId" : playlistId, 
                                @"playlistName" : playlistName, 
                                @"userDisplayName" : userDisplayName 
                                }; 

        [newUserPlaylistUrlRef setValue:dict withCompletionBlock:^(NSError * _Nullable error, FIRDatabaseReference * _Nonnull ref) { 

            //completion block not called, this code is never reached...
            completionBlock(key, error);  

        }]; 
    } 
}
  • 我已连接到互联网
  • 将数据写入服务器:

setValue之后的Firebase控制台的屏幕截图:

screenshot of the firebase console right after the setValue

以下是setValue之后的XCode中的firebase日志:

2016-10-07 18:53:54.775 Metalplay PREPROD[1157:833315] [FirebaseDatabase] Setting: /plr-playlist-url/plr-user-playlist-url/-KTVGurwKGAvnSglB88N with {
    playlistId = "-KTK7289xor0Fba6Y3SW";
    playlistName = TITO;
    userDisplayName = eussam3;
} pri: <null>
2016-10-07 18:53:54.777 Metalplay PREPROD[1157:833315] [FirebaseDatabase] Was connected, and added as index: 4
2016-10-07 18:53:54.779 Metalplay PREPROD[1157:833315] [FirebaseDatabase] Sending: {
    d =     {
        a = p;
        b =         {
            d =             {
                playlistId = "-KTK7289xor0Fba6Y3SW";
                playlistName = TITO;
                userDisplayName = eussam3;
            };
            p = "/plr-playlist-url/plr-user-playlist-url/-KTVGurwKGAvnSglB88N";
        };
        r = 15;
    };
    t = d;
}
2016-10-07 18:53:54.780 Metalplay PREPROD[1157:833315] [FirebaseDatabase] (wsc:3) resetting keepalive, to 2016-10-07 17:54:39 +0000 ; old: 2016-10-07 17:54:22 +0000
2016-10-07 18:53:55.011 Metalplay PREPROD[1157:833347] [FirebaseDatabase] (wsc:3) handleNewFrameCount: 1
2016-10-07 18:53:55.012 Metalplay PREPROD[1157:833347] [FirebaseDatabase] (wsc:3) handleIncomingFrame sending complete frame: 0
2016-10-07 18:53:55.012 Metalplay PREPROD[1157:833347] [FirebaseDatabase] Got data message: {
    b =     {
        d = "";
        s = ok;
    };
    r = 15;
}
2016-10-07 18:54:39.781 Metalplay PREPROD[1157:832417] [FirebaseDatabase] (wsc:3) nop

你能告诉我我做错了什么吗?

更新:

以下是该方法的简化版本,仅在执行完成块时在控制台上显示日志:

- (void)addShortUserPlaylistUrl:(NSString *)playlistId
                   playlistName:(NSString *)playlistName
                userDisplayName:(NSString *)userDisplayName
                completionBlock:(ObjectBlock)completionBlock
{
    FIRDatabaseReference *newUserPlaylistUrlRef = [[_root child:KPLRUserPlaylistUrlRef] childByAutoId];
    if (newUserPlaylistUrlRef != nil) {

        NSString *key = [newUserPlaylistUrlRef key];

        NSDictionary *dict = @{ @"playlistId" : playlistId,
                                @"playlistName" : playlistName,
                                @"userDisplayName" : userDisplayName
                                };

        [newUserPlaylistUrlRef setValue:dict withCompletionBlock:^(NSError * _Nullable error, FIRDatabaseReference * _Nonnull ref) {

            NSLog(@"---- FirebaseManager::addShortUserPlaylistUrl completionBlock called - key: %@", key);

        }];
    }
}

刚试过模拟器:

  • 块内的NSLog未执行
  • setValue在服务器上完成,如firebase控制台屏幕截图所示:

firebase console

xcode控制台显示:

2016-10-07 23:01:09.881 Metalplay PREPROD[45490:2301640] [FirebaseDatabase] Setting: /plr-playlist-url/plr-user-playlist-url/-KTW9VhscuqEfYYu1qh- with {
    playlistId = "-KTK5lFek22awzKaVCpU";
    playlistName = Toto;
    userDisplayName = eussam3;
} pri: <null>
2016-10-07 23:01:09.882 Metalplay PREPROD[45490:2301640] [FirebaseDatabase] Was connected, and added as index: 1
2016-10-07 23:01:09.882 Metalplay PREPROD[45490:2301640] [FirebaseDatabase] Sending: {
    d =     {
        a = p;
        b =         {
            d =             {
                playlistId = "-KTK5lFek22awzKaVCpU";
                playlistName = Toto;
                userDisplayName = eussam3;
            };
            p = "/plr-playlist-url/plr-user-playlist-url/-KTW9VhscuqEfYYu1qh-";
        };
        r = 12;
    };
    t = d;
}
2016-10-07 23:01:09.882 Metalplay PREPROD[45490:2301640] [FirebaseDatabase] (wsc:2) resetting keepalive, to 2016-10-07 22:01:54 +0000 ; old: 2016-10-07 22:01:40 +0000
2016-10-07 23:01:10.020 Metalplay PREPROD[45490:2301477] [FirebaseDatabase] (wsc:2) handleNewFrameCount: 1
2016-10-07 23:01:10.021 Metalplay PREPROD[45490:2301477] [FirebaseDatabase] (wsc:2) handleIncomingFrame sending complete frame: 0
2016-10-07 23:01:10.021 Metalplay PREPROD[45490:2301477] [FirebaseDatabase] Got data message: {
    b =     {
        d = "";
        s = ok;
    };
    r = 12;
}

以下是使用的版本号:

---------------------------------
MacBook-Pro-de-eussam:PLR eussam$ pod install
Analyzing dependencies
Downloading dependencies
Using Firebase (3.4.0)
Using FirebaseAnalytics (3.3.0)
Using FirebaseAuth (3.0.4)
Using FirebaseDatabase (3.0.2)
Using FirebaseInstanceID (1.0.8)
Using GTMSessionFetcher (1.1.6)
Using GoogleAPIClientForREST (1.0.2)
Using GoogleInterchangeUtilities (1.2.1)
Using GoogleNetworkingUtilities (1.2.1)
Using GoogleParsingUtilities (1.1.1)
Using GoogleSymbolUtilities (1.1.1)
Using GoogleUtilities (1.3.1)
Using SDWebImage (3.8.1)
Using Toast (3.0)
Using youtube-ios-player-helper (0.1.6)
Generating Pods project
Integrating client project
Pod installation complete! There are 7 dependencies from the Podfile and 15 total pods installed.

0 个答案:

没有答案