IOS XCODE5 Database Connection Error on LeaderBoard

0 votes

Hello i am trying to implement the leaderboard into my project but keep getting database error i added all the data as in tutorial on my LDConstants.h file but cant find the db name the correct on isnt it working somehow like mysql i think i should create the db inside the game panel but dont know how.. i copied all the files as in tut and created a new uiviewcontroler inside my storyboard instead of using the Xib file designed it to look the same and hooked all the methods and action buttos etc. as on the sample project but when i am in main menu and click the button i have to send me over to that screen i get this error .

can somebody help me ? how to create db and how to correctly connect all together? i want a simple login in settings and then a diferent button for leaderboard that the could check on it thats all ;/ 

thanks a lot any help would be much apreciate! 

 

 

*** Terminating app due to uncaught exception 'Database Name', reason: 'Database Name : parameter can't be blank.'

*** First throw call stack:

(

0   CoreFoundation                      0x0238a1e4 __exceptionPreprocess + 180

1   libobjc.A.dylib                     0x021098e5 objc_exception_throw + 44

2   Quiz                                0x00022451 +[Utils validateMax:] + 0

3   Quiz                                0x00093019 -[App42Service setQuery:metaInfoQuery:] + 80

4   Quiz                                0x0000dcc4 -[App42Helper getScores] + 132

5   Quiz                                0x00014eaf __25-[LDLeaderBoard getScore]_block_invoke + 143

6   libdispatch.dylib                   0x026897b8 _dispatch_call_block_and_release + 15

7   libdispatch.dylib                   0x0269e4d0 _dispatch_client_callout + 14

8   libdispatch.dylib                   0x0268ceb7 _dispatch_root_queue_drain + 291

9   libdispatch.dylib                   0x0268d127 _dispatch_worker_thread2 + 39

10  libsystem_pthread.dylib             0x029cddab _pthread_wqthread + 336

11  libsystem_pthread.dylib             0x029d1cce start_wqthread + 30

)

libc++abi.dylib: terminating with uncaught exception of type App42Exception

2014-06-13 00:09:06.857 Quiz[1937:60b] -[LDLeaderBoard numberOfSectionsInTableView:]

asked Jun 12, 2014 in App42 Cloud API-BaaS by simoslaftsoglou (10 points)

1 Answer

0 votes

Hi,

If you have created an App on Shephertz Dashboard-AppHQ, then you need to create db from there for that app(Refer this). For more understanding of Storage Service you can go through this tutorial. Then provide DB_NAME that you created in LDConstants.h class. Also you need to provide COLLECTION_NAME that can be any name of your choice.

 

EDITED:

In the Sample source code, open App42Helper.m -> search for the method initializeApp42. Please cross verify you are doing both steps done in that method.

- (void)initializeApp42 {

    [App42API initializeWithAPIKey:APP42_APP_KEY andSecretKey:APP42_SECRET_KEY];

    [App42API setDbName:DB_NAME];

}

After initializing App42API, you have to set DB_NAME. I think this missing.

Thanks.

answered Jun 13, 2014 by rajeev.etc (1,660 points)
edited Jun 13, 2014 by rajeev.etc
Hi,
Can you let me know what is your requirement, so that i can suggest you best way to achieve that.
Can you share the code which you are using to get scores from the server. It will help in finding the main reason of crash. I guess some parameter is missing that the table view delegate is trying to fetch.
Thanks.
Hi
i Guess this is the method the game uses to get fb scores and scores
what i am after is almost the same as the sample.. post scores to fb and to leaderboard simultaneously and an option to share on fb as well if user wants .. the leaderboard as it is global highscores and fb friends highscores thats it but i don't get it how do i get the scores of my game to understand this method so it'll work as the sample ? i mean my score int . what do it have to change on the savescore method to make it work with my project?
thanks !

i -(BOOL)saveScore {
    BOOL _success = false;
    @try {
        NSString *name = [[PWFacebookHelper sharedInstance] userName];
        ScoreBoardService *scoreboardService = [App42API buildScoreBoardService];
        NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:_userID,@"UserID",[NSNumber numberWithInt:_score],@"Score",name,@"Name", nil];
        [scoreboardService addCustomScore:dict collectionName:COLLECTION_NAME];

        Game *game=[scoreboardService saveUserScore:GAME_NAME gameUserName:_userID gameScore:_score];
        if(game.isResponseSuccess) {
            NSLog(@"saveScore Success");
            _success = true;
        }
    }
    @catch (App42Exception *exception) {
        NSLog(@"%@",[exception description]);
    }
    return _success;
}

-(NSMutableArray*)getScores {
    ScoreBoardService *scoreboardService = [App42API buildScoreBoardService];
    [scoreboardService setQuery:COLLECTION_NAME metaInfoQuery:Nil];

    Game *game=[scoreboardService getTopNRankers:GAME_NAME max:MAX_NUMBER_OF_RECORDS_DISPLAYED_IN_LB];
    NSMutableArray *scoreList = game.scoreList;
    return scoreList;
}

-(NSMutableArray *) getFBFriendScores {
    ScoreBoardService *scoreboardService = [App42API buildScoreBoardService];
    [scoreboardService setQuery:COLLECTION_NAME metaInfoQuery:Nil];
    
    NSString *accessToken = [[[[PWFacebookHelper sharedInstance] loggedInSession] accessTokenData] accessToken];
    Game *game=[scoreboardService getTopNRankersFromFacebook:GAME_NAME fbAccessToken:accessToken max:MAX_NUMBER_OF_RECORDS_DISPLAYED_IN_LB];
    NSMutableArray *scoreList = game.scoreList;
    return scoreList;
}
Hi,

In the tableview datasource method: cellForRowAtIndexPath, there is variable called metaArray. It is possible that the array is coming empty as the record does not have any meta data for that particular user and in that case it will crash.
You try replacing the codes just after the statement
NSArray *metaArray = [l_score jsonDocArray];,    

with the following code:
 if (metaArray.count)
 {
        NSString *jsonString = [(JSONDocument *)[metaArray objectAtIndex:0] jsonDoc];
        NSLog(@"jsonString=%@",jsonString);
        NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableLeaves error:nil];
        [self loadProfileImageForId:[jsonDict objectForKey:@"UserID"] onImageView:(UIImageView *)[cell viewWithTag:1]];
        [(UILabel *)[cell viewWithTag:2] setText:[jsonDict objectForKey:@"Name"]];
        [(UILabel *)[cell viewWithTag:3] setText:[NSString stringWithFormat:@"%d",indexPath.row+1]];
        [(UILabel *)[cell viewWithTag:4] setText:[NSString stringWithFormat:@"%0.0f",[[jsonDict objectForKey:@"Score"] floatValue]]];
}


What i am doing is in this code is just handling the case in which metaArray may come empty by putting codes that is trying to use metaArray data in a IF BLOCK that check for the metaArray is empty or not.
Alright thanks for the Rajeev seemed to do the trick and worked as it should my main headache right now is how to implement it on my project .. i copied everything over as from the sample i have the int. score  and i @synthesize it couse i use custom fonts i see the project uses only code to create fb button and so on but i use storyboard layouts what can i do to just use my fb button on game over to post my score to fb and to the dashboard i already have a fb login on my settings which works with Facebook SDK and a button to show the leaderboard but whatever i try i can't make it work from the sample its all completely different :/ any suggestions to do that ? thanks
Leaderboard Sample does not post score to fb, it uses the the fb user_id to save the the score to App42 to make the user name unique for every user. Sample is asking to login to facebook to fetch the user_id.

Sample just shows how the features of App42 can be utilised in the games, but it is not recommended to copy paste the codes in your project as it might not be compatible. What you should do is understand the integration of App42 leaderboard and use it as per your requirement.

I gave you a simple project earlier to show the App42 integration in the easier way.

Coming to your doubts, it is not necessary to place the fb button on the game over screen. If you have a login button in some other screen, you can login from there and save the user_id that can be used later on as user name while saving the score to App42 leaderboard.

Let me know if you have any further doubts.
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...