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
Thanks a lot for you answer just wanted to ask is it possible that i have to enter more than the LDConstant.h file the database name ? i did everything insert JSON as well though i didn't really understand it but just made a simple  last name: name : and score rows but still keep getting the same error that database can't be blank  :/ the pdf that explains how to integrate says something about app delegate.m file to insert there as well but even with it still the same
any suggestions ? thanks a lot for your help again !
I have updated my answer, can you check once if that step is missing.
Hi and thanks for you time Rajeev i did what you told me it seemed to work i get the NSlog that i connect successfully but the error i get now is that i haven't created any game even though i have 2 games tried both do i have to create any specific JSON query before i can start using it ? or what do u suggest might be the problem ?
Thanks a lotttt!!!!

 *** Terminating app due to uncaught exception 'App42NotFoundException', reason: '{"app42Fault":{"httpErrorCode":404,"appErrorCode":3002,"message":"Not Found","details":"Game with the name 'BubbleQuiz' does not exist."}}'
Make sure you have created 'BubbleQuiz' game in the dashboard. If not then first create a game to which you want to submit your score. I am attaching dashboard screenshot for your reference: http://cdn.shephertz.com/repository/files/cad2bfab6310acd9696187b98682925125e469ab0d0d585db0b00609f461b791/4aebde8594f8c9e6e17550fd8ad81c00d3e6c650/CreateGame.png
i have created it otherwise i wouldn't be able to create the db as well i created 2 games already getting same result each time any other suggestion ? thanks a lot!
Oh and i just saw i have a hit displayed on my API hits guess that means i connect successfully ? can you tell me if thats easy how to bridge to the xib file directly from storyboard? maybe this is causing the problem because i try to recreate the file in the storyboard?

P.S
Please could somebody be so kind and explain to me in simple words how to connect it correctly its a xib file and i use storyboard don't really know how to connect it together correctly...tried to give create new viewcontroler with the class of the xib and recreate all objects like it was given... tried everything and fail i used container as well and when i load it still getting can't find game error even though i have the game setup inside my app any help ? I'm really close to give up on this i created faster the game of my app than connect a theoretically easy sdk for social integration and leaderboard :(
Hi,

Can you share the code snippet you are trying, it will be helpful to debug the problem.

Thanks.
Hi,
I have created a sample project that has only 3-4 API calls to make the understanding of integration of App42API more clear. You can download the sample from my github repo: https://github.com/RajeevRShephertz/App42APICodeSamples .

Follow the ReadMe file for better understanding of the sample.
Let me know if you face any further problem.
Thanks.
Hi Rajeev thanks a lot for your effort but i really thinking of giving up it exhausting .. :/ i downloaded the sample worked great created new game and all and every things perfect getting call backs so np with database ..got a new clean copy or the leaderboard sample start clean all over with my credentials from fb and the app add fb settings in dashboard I'm getting  back all my fb data connect correctly but always getting oops failed to submit score :( and no new rows of my name or anything in dashboard i just wanted a simple leaderboard and the fb login button in my settings section thats it :/ ill just give up to hard for me .. can u suggest anyone that could do it for me ? and how much do you think itl cost me ? maybe after i publish it as is ill do it like that
But thanks for you great help your amazing !
You mean, you are not able to submit score to the database using "saveUserScore" API. If so, can you share the response you are getting from the Server. You can also check the SDK internal logs by enablingTrace that i have done in the sample in initializeApp42 method. Can you share the logs with me, it will be helpful to detect the problem.
Yeah i just managed to make it submit the score but while i try to enter the leaderboard it crashes and i use the default game from app42 heres my log
thanks a gain for the support
2014-06-16 22:09:20.678 SpacePowerCombat[2781:60b] openSessionWithAllowLoginUI response
2014-06-16 22:09:20.680 SpacePowerCombat[2781:60b] userInfoDict={
    "first_name" = Simeon;
    gender = male;
    id = 388**************;
    "last_name" = Laftsoglou;
    link = "https://www.facebook.com/app_scoped_user_id/388573654614477/";
    locale = "el_GR";
    name = "Simeon Laftsoglou";
    timezone = 3;
    "updated_time" = "2014-05-30T21:52:33+0000";
    verified = 1;
}
2014-06-16 22:09:20.681 SpacePowerCombat[2781:60b] -[LDGameOverScene userDidLoggedIn]
2014-06-16 22:09:20.681 SpacePowerCombat[2781:60b] 388573654614477
2014-06-16 22:09:20.682 SpacePowerCombat[2781:60b] self.userName=Simeon
2014-06-16 22:09:20.706 SpacePowerCombat[2781:60b] error=(null)
2014-06-16 22:09:24.550 SpacePowerCombat[2781:3207] saveScore Success
2014-06-16 22:09:28.669 SpacePowerCombat[2781:60b] -[LDLeaderBoard numberOfSectionsInTableView:]
2014-06-16 22:09:29.468 SpacePowerCombat[2781:3207] scoreList=(
    "<Score: 0xa9d1fc0>",
    "<Score: 0x13663510>"
)
2014-06-16 22:09:29.468 SpacePowerCombat[2781:60b] -[LDLeaderBoard numberOfSectionsInTableView:]
2014-06-16 22:09:29.498 SpacePowerCombat[2781:60b] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(
    0   CoreFoundation                      0x01d471e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x01ac68e5 objc_exception_throw + 44
    2   CoreFoundation                      0x01ce83f6 -[__NSArrayM objectAtIndex:] + 246
    3   SpacePowerCombat                    0x0000f90e -[LDLeaderBoard tableView:cellForRowAtIndexPath:] + 4014
    4   UIKit                               0x0087f11f -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 412
    5   UIKit                               0x0087f1f3 -[UITableView _createPreparedCellForGlobalRow:] + 69
    6   UIKit                               0x00860ece -[UITableView _updateVisibleCellsNow:] + 2428
    7   UIKit                               0x008756a5 -[UITableView layoutSubviews] + 213
    8   UIKit                               0x007f5964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
    9   libobjc.A.dylib                     0x01ad882b -[NSObject performSelector:withObject:] + 70
    10  QuartzCore                          0x050cd45a -[CALayer layoutSublayers] + 148
    11  QuartzCore                          0x050c1244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
    12  QuartzCore                          0x050c10b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
    13  QuartzCore                          0x050277fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
    14  QuartzCore                          0x05028b85 _ZN2CA11Transaction6commitEv + 393
    15  QuartzCore                          0x05029258 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
    16  CoreFoundation                      0x01d0f36e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
    17  CoreFoundation                      0x01d0f2bf __CFRunLoopDoObservers + 399
    18  CoreFoundation                      0x01ced254 __CFRunLoopRun + 1076
    19  CoreFoundation                      0x01cec9d3 CFRunLoopRunSpecific + 467
    20  CoreFoundation                      0x01cec7eb CFRunLoopRunInMode + 123
    21  GraphicsServices                    0x022db5ee GSEventRunModal + 192
    22  GraphicsServices                    0x022db42b GSEventRun + 104
    23  UIKit                               0x00786f9b UIApplicationMain + 1225
    24  SpacePowerCombat                    0x00008bfd main + 141
    25  libdyld.dylib                       0x0319e701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
The crash logs says that the method "[LDLeaderBoard tableView:cellForRowAtIndexPath:] " is trying to access object from an array beyond its bound.
If you can send the code, i can help you in debug.
Hi heres the table view code it is the same file from spacePowerCombat file i havent really changed anything ..maybe something to do with JSON ? haven't created any as far as i understood they get created automatically?
the code
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if (tableView) {
        NSLog(@"%s",__func__);
        // Return the number of sections.
        return 1;
    }
    return 0;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    int numberOfRows =0;
    if (scoreList) {
        numberOfRows =[scoreList count];
    }
    return numberOfRows;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        CGSize viewSize = leaderboardTableView.frame.size;
        float labelWidth = viewSize.width/3;
        float x_pos = 5;
        float y_pos = 15;
        
        int fontSize = 24;
        
        if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone) {
            x_pos = 2;
            y_pos = 3;
            fontSize = 16;
        }
        
        UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, viewSize.width, rowHeight)];
        
        bgView.tag=5;
        [cell addSubview:bgView];
        
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(x_pos, 2, rowHeight-4, rowHeight-4)];
        imageView.tag = 1;
        [cell addSubview:imageView];
        
        x_pos +=imageView.frame.size.width;
        UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(x_pos, y_pos, labelWidth, 30)];
        nameLabel.backgroundColor = [UIColor clearColor];
        nameLabel.tag =2;
        nameLabel.font = [UIFont fontWithName:@"MarkerFelt-Wide" size:fontSize];
        nameLabel.textAlignment = NSTextAlignmentCenter;
        [nameLabel setTextColor:[UIColor whiteColor]];
        [cell addSubview:nameLabel];
        
        x_pos +=labelWidth/1.5;
        UILabel *rankLabel = [[UILabel alloc] initWithFrame:CGRectMake(x_pos, y_pos, labelWidth, 30)];
        rankLabel.backgroundColor = [UIColor clearColor];
        rankLabel.tag =3;
        rankLabel.font = [UIFont fontWithName:@"MarkerFelt-Wide" size:fontSize];
        rankLabel.textAlignment = NSTextAlignmentCenter;
        [rankLabel setTextColor:[UIColor whiteColor]];
        [cell addSubview:rankLabel];
        
        x_pos +=labelWidth;
        UILabel *scoreLabel = [[UILabel alloc] initWithFrame:CGRectMake(x_pos, y_pos, labelWidth, 30)];
        scoreLabel.backgroundColor = [UIColor clearColor];
        scoreLabel.tag =4;
        scoreLabel.font = [UIFont fontWithName:@"MarkerFelt-Wide" size:fontSize];
        scoreLabel.textAlignment = NSTextAlignmentCenter;
        [scoreLabel setTextColor:[UIColor whiteColor]];
        [cell addSubview:scoreLabel];
        
    }
    
    Score *l_score = [scoreList objectAtIndex:indexPath.row];
    NSArray *metaArray = [l_score jsonDocArray];
    NSString *jsonString = [(JSONDocument *)[metaArray objectAtIndex:0] jsonDoc];
    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]]];
    
    UIView *bgview = (UIView *)[cell viewWithTag:5];
    if (indexPath.row%2==0) {
        bgview.backgroundColor = [UIColor colorWithRed:184.0f/255.0f green:143.0f/255.0f blue:19.0f/255.0f alpha:1.0f];
    } else {
        bgview.backgroundColor = [UIColor colorWithRed:183.0f/255.0f green:106.0f/255.0f blue:15.0f/255.0f alpha:1.0f];
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone) {
        rowHeight = 36;
    } else {
        rowHeight = 54;
    }
    return rowHeight;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSLog(@"%s",__func__);
}
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
...