How can I change the order of iOS Kif tests? - iphone

As far as I can tell the tests in my KIFTestScenario+EXAdditions just go in alphabetical order. How can I get the tests to go in an order that I want. I would rather not simply name them like this scenarioToATestLogin.
Thanks!

We used to have that problem, but now we subclass the KifTestController, and in that controller we add our KifTestScenario's like this:
- (void)initializeScenarios {
[self addScenario:[KIFTestScenario scenarioTestMediaPlayer]];
[self addScenario:[KIFTestScenario scenarioTestVideoPlayer]];
[self addScenario:[KIFTestScenario scenarioTestSharing]];
[self addScenario:[KIFTestScenario scenarioTestContentView]];
}
Then in our AppDelegate, we start up the KiffTest's in this method:
- (void)runIntegrationTests {
[[OurTestController sharedInstance] startTestingWithCompletionBlock:^{
exit([[OurTestController sharedInstance] failureCount]);
}];
}
And our scenarios run in the order that we have added them above.

Related

Implement game center, and "missed method" error [duplicate]

Apologies ahead of time if this is a completely off-the-mark question, or if I'm not including enough information - I'm very new to iOS development (and Objective-C), and have a habit of jumping into the deep end...
I'm having trouble understanding the "callDelegate" code in GameCenterManager.m that's in the GKTapper Sample Code and also provided in this tuts+ tutorial: http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-game-center-achievements-and-leaderboards-part-2/
This is the code:
- (void) callDelegate: (SEL) selector withArg: (id) arg error: (NSError*) err
{
assert([NSThread isMainThread]);
if([delegate respondsToSelector: selector])
{
if(arg != NULL)
{
[delegate performSelector: selector withObject: arg withObject: err];
}
else
{
[delegate performSelector: selector withObject: err];
}
}
else
{
NSLog(#"Missed Method");
}
}
My app always logs that "Missed Method" line, but I'm not sure what this callDelegate code is actually doing (so I can't fix it). I figure the best way forward is to learn what this is actually doing, and get better output than 'Missed Method'...
One caveat is that my app is currently using Game Center in sandbox mode, since I'm still developing it. This 'Missed Method' line might be expected in this situation - I'm not sure of that, either.
Would anybody be able to translate this code into paragraph form? I'm particularly unsure about the '[delegate respondsToSelector: selector]' piece.
Alternatively, would anybody be able to rewrite the NSLog line so that it outputs more/relevant detail about the problem? I tried this in the hopes of seeing which selector is not going through 'respondsToSelector' properly, but it didn't seem to work:
NSLog(#"Missed Method, %#", selector);
T'he best way to see exactly what is happening is putting a breakpoint at the beginning of callDelegate and then debugging your program, instead of simply running it. You can debug by pressing cmd-y.
Doing like this, each time your program enters the callDelegate function, it stops and the debugger window pops up. There you will be able to inspect where the call came from and what the parameters are.
As to a plain description of this function I would say that it is an helper function that wraps a call to a selector by preceding it with a check of existence of that selector. Instead of checking each time and the performing the selector, you call the helper function that will do both things for you.
So, the reason you always see the log line is that the function you would like to call is not there. By using the debugger you will be able to see which function it is, which class is missing it, and who attempted the operation.
Some comments requested further details about what I commented out to resolve this issue. I didn't think this was good to add as an edit to the question, since it specifically goes over the resolution. It's been a while since I've worked on this project, so it's not all at the top of my head & I'm not sure I've done everything correctly ... I'll do my best to explain it, though.
In the file GameCenterManager.h, it looks like authenticateLocalUser is being initialized:
- (void) authenticateLocalUser;
In the file App_NameViewController.m, viewDidLoad is checking to see if Game Center is available:
self.currentLeaderBoard = kLeaderboardID;
if ([GameCenterManager isGameCenterAvailable]) {
self.gameCenterManager = [[[GameCenterManager alloc] init] autorelease];
[self.gameCenterManager setDelegate:self];
[self.gameCenterManager authenticateLocalUser];
} else {
// The current device does not support Game Center.
}
In the file GameCenterManager.m
- (void) authenticateLocalUser
{
if([GKLocalPlayer localPlayer].authenticated == NO)
{
[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error)
{
// report any unreported scores or achievements
[self retrieveScoresFromDevice];
[self retrieveAchievementsFromDevice];
//[self callDelegateOnMainThread: #selector(processGameCenterAuth:) withArg: NULL error: error];
}];
}
}
The line that I commented out, which moved me past the Missed Method error, was:
[self callDelegateOnMainThread: #selector(processGameCenterAuth:) withArg: NULL error: error];
I hope this helps!
Add this code to Game_CenterViewController.m you will see the error
- (void)processGameCenterAuth:(NSError *)error{
NSLog(#"error %#", error);
}

Using Cocos2D scheduleUpdate to delay loading

I have an algorithm that takes a few seconds to load some stuff, and I want to first set the string on a label to say "loading" before the actual loading begins. This is all within the same layer, this is not switching between scenes.
I thought I could simply do this:
-(void)startLoading{
[self unscheduleAllSelectors];//just in case the update is already scheduled
[self.loadingLabel setString:#"Loading...."];
[self scheduleUpdate];
}
Then, I have this:
-(void)update:(ccTime)delta{
[self unscheduleUpdate];
[self beginLoading];//another method that loads all the stuff
}
My understanding is that my method beginLoading should not run until the next frame. Thus my label should get updated correctly. However this is not happening. There is a slight freeze while all my assets get loaded and my label never gets updated before the loading begins.
Am I missing a step?
Nope ure not missing anything. I stopped fighting this and now use this kind of 'delayed' task catapult. It should make certain you will get a draw in the transition from the first to the second tick:
-(void) startLoading{
_loadTicker=0; // an NSUInteger iVar declared in the .h
[self schedule:#selector(tickOffLoading:)];
}
-(void) tickOffLoading:(ccTime) dt{
_loadTicker++;
if(_loadTicker==1) {
[self.loadingLabel setString:#"Loading...."];
} else {
[self unschedule:#selector(tickOffLoading:)];
[self beginLoading];
}
}

iPhone GameCenter won't showAchievments

So my problem is that after integrating gamecenter nicely into my iphone app, it won't show the achievements list!
The integration was a success I think because when I use the submitAchievement method, I do unlock achievements on the list. But I must look at the list from the GameCenter App on the iPhone, not within my own app as it doesn't work.
ikuragames first help me get the code right (thx you !!) but it still doesn't work ! :(
-(void)showAchievments
{
//NSLog(#"showAchievments");
GKAchievementViewController *achievements = [GKAchievementViewController alloc] init];
if (achievements != nil)
{
achievements.achievementDelegate = self;
[(EAGLView *)self.view achievmentsWillAppear];
[self presentModalViewController:achievements animated:YES];
}
}
- (void)achievementViewControllerDidFinish:(GKAchievementViewController *)viewController
{
//NSLog(#"achievementViewControllerDidFinish");
[glView achievmentsWillDisappear];
[self dismissModalViewControllerAnimated:YES];
}
On debug mode, I can clearly see that each line or code are "processed" and not error whatsoever is displayed. BUT, nothing appears on my screen :(
Can you please help me ? (here is some doc.)
I found the answer.
Turned out that the view controller I was sending showAchievments to was not the view controller I wanted.
I was doing something like:
[[myViewController sharedInstance] showAchievments];
But the sharedInstance method returned a brand-new, vanilla-initialised myViewController, and not the one I was already using.
Now it works perfectly, I hope this will help someone in the future.

cocos2d schedule selector error

i have an error when scheduling a method. (to display how many star you get according to your score. i have addStar0 addStar1 addStar2 addStar3 methods)
[self schedule:#selector(addStar0) interval:0.2f];
and the methods are:
-(void) addstar0 {
[self unschedule:_cmd];
if (star > starProgress) {
starProgress++;
[self schedule:#selector(addStar1) interval:0.5f];
}
else {
[self schedule:#selector(displayResult) interval:0.5f];
}
}
error message:
Signature not found for selector - does it have the following form? -(void) name: (ccTime) dt
I've tried changing all my methods into addStar1: (ccTime) delta and schedule: #selector(addStar:) interval: 0.2f, but still the same. (actually i've used both ways to schedule( with/without parameter), and both of them worked well in my last project. )
also, one weird thing: sometimes i can't use [self schedule: something], but [CCScheduler sharedScheduler] schedule: something] works fine. I guess it may be project settings or so?
Please answer it with code. thank you.
You are using 'addStar0' for selector
[self schedule:#selector(addStar0) interval:0.2f];
then
-(void) addstar0 {
should be
-(void) addStar0 {
I think your error is actually on [self unschedule:_cmd];
Where is _cmd defined? Try commenting out that line and running it again.
put [self unschedule:_cmd]; after the else statement

What causes "Missed Method" in this code?

Apologies ahead of time if this is a completely off-the-mark question, or if I'm not including enough information - I'm very new to iOS development (and Objective-C), and have a habit of jumping into the deep end...
I'm having trouble understanding the "callDelegate" code in GameCenterManager.m that's in the GKTapper Sample Code and also provided in this tuts+ tutorial: http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-game-center-achievements-and-leaderboards-part-2/
This is the code:
- (void) callDelegate: (SEL) selector withArg: (id) arg error: (NSError*) err
{
assert([NSThread isMainThread]);
if([delegate respondsToSelector: selector])
{
if(arg != NULL)
{
[delegate performSelector: selector withObject: arg withObject: err];
}
else
{
[delegate performSelector: selector withObject: err];
}
}
else
{
NSLog(#"Missed Method");
}
}
My app always logs that "Missed Method" line, but I'm not sure what this callDelegate code is actually doing (so I can't fix it). I figure the best way forward is to learn what this is actually doing, and get better output than 'Missed Method'...
One caveat is that my app is currently using Game Center in sandbox mode, since I'm still developing it. This 'Missed Method' line might be expected in this situation - I'm not sure of that, either.
Would anybody be able to translate this code into paragraph form? I'm particularly unsure about the '[delegate respondsToSelector: selector]' piece.
Alternatively, would anybody be able to rewrite the NSLog line so that it outputs more/relevant detail about the problem? I tried this in the hopes of seeing which selector is not going through 'respondsToSelector' properly, but it didn't seem to work:
NSLog(#"Missed Method, %#", selector);
T'he best way to see exactly what is happening is putting a breakpoint at the beginning of callDelegate and then debugging your program, instead of simply running it. You can debug by pressing cmd-y.
Doing like this, each time your program enters the callDelegate function, it stops and the debugger window pops up. There you will be able to inspect where the call came from and what the parameters are.
As to a plain description of this function I would say that it is an helper function that wraps a call to a selector by preceding it with a check of existence of that selector. Instead of checking each time and the performing the selector, you call the helper function that will do both things for you.
So, the reason you always see the log line is that the function you would like to call is not there. By using the debugger you will be able to see which function it is, which class is missing it, and who attempted the operation.
Some comments requested further details about what I commented out to resolve this issue. I didn't think this was good to add as an edit to the question, since it specifically goes over the resolution. It's been a while since I've worked on this project, so it's not all at the top of my head & I'm not sure I've done everything correctly ... I'll do my best to explain it, though.
In the file GameCenterManager.h, it looks like authenticateLocalUser is being initialized:
- (void) authenticateLocalUser;
In the file App_NameViewController.m, viewDidLoad is checking to see if Game Center is available:
self.currentLeaderBoard = kLeaderboardID;
if ([GameCenterManager isGameCenterAvailable]) {
self.gameCenterManager = [[[GameCenterManager alloc] init] autorelease];
[self.gameCenterManager setDelegate:self];
[self.gameCenterManager authenticateLocalUser];
} else {
// The current device does not support Game Center.
}
In the file GameCenterManager.m
- (void) authenticateLocalUser
{
if([GKLocalPlayer localPlayer].authenticated == NO)
{
[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error)
{
// report any unreported scores or achievements
[self retrieveScoresFromDevice];
[self retrieveAchievementsFromDevice];
//[self callDelegateOnMainThread: #selector(processGameCenterAuth:) withArg: NULL error: error];
}];
}
}
The line that I commented out, which moved me past the Missed Method error, was:
[self callDelegateOnMainThread: #selector(processGameCenterAuth:) withArg: NULL error: error];
I hope this helps!
Add this code to Game_CenterViewController.m you will see the error
- (void)processGameCenterAuth:(NSError *)error{
NSLog(#"error %#", error);
}