Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-02-2011, 06:27 PM   #1 (permalink)
Registered Member
 
Join Date: Apr 2010
Location: Germany
Posts: 56
Applekuchen is on a distinguished road
Default pause game when push notification appears

hey there,

i've got a big problem. i want that my game pauses when a push notification appears and when i go on it should go on.

so i've got my pauseGame method:

Code:
-(IBAction)pauseGame {

if (pause == NO) {

    [myTimer invalidate];

    button.enabled = NO;


    [stopButton setImage: [UIImage imageNamed: @"play@2x.png"] forState:UIControlStateNormal];

    pause = YES;
}

else {

    [self start];

    button.enabled = YES;

    [stopButton setImage: [UIImage imageNamed: @"pause@2x.png"] forState:UIControlStateNormal];

    pause = NO;
}
}
i've got this method in three different view controllers, so i've done this in my appDelegate:

Code:
- (void)applicationWillResignActive:(UIApplication *)application {
	
[FirstViewController pauseGame];
[SecondViewController pauseGame];
[ThirdViewController pauseGame];

	
}
Code:
- (void)applicationDidBecomeActive:(UIApplication *)application {

[FirstViewController pauseGame];
[SecondViewController pauseGame];
[ThirdViewController pauseGame];		
	
}
Now, when i start the app, it crashes, what's wrong about this?

Thanks
Applekuchen is offline   Reply With Quote
Old 04-02-2011, 06:48 PM   #2 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

You need to describe your problem better. What's the crash log in the console?

1. Why are three view controllers active at the same time?
2. There's also a 'application:didReceiveRemoteNotification:' method in the app delegate that is invoked if your app is running at the time you receive the notification.
3. You shouldn't be passing the @2x suffix explicitly. It's up to iOS to look for it and choose the right image file (low or high res) depending on which device the app is running.
baja_yu is offline   Reply With Quote
Old 04-02-2011, 07:00 PM   #3 (permalink)
Registered Member
 
Join Date: Apr 2010
Location: Germany
Posts: 56
Applekuchen is on a distinguished road
Default

1. They aren't active at the same time, but i have to include all three otherwise it wouldn't work in all three viewcontrollers, would it?
Because I can't know which viewcontroller is active at the moment.
2. where's the difference?
3. sorry about that, thanks
Applekuchen is offline   Reply With Quote
Old 04-02-2011, 08:46 PM   #4 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

1. How can you send a message to an object that doesn't exist? Again, look in the console and see what exception is being thrown, that's the clue to where the problem is. Why do you have three different controllers for gameplay? Generally you have one that you customize based on the game contents at the time. I can't give you specific suggestions because I have no idea about what the contents of those nibs are or how you structured the app.
2. If the app is running and you want to receive push notifications, you have to code it in that method.
baja_yu is offline   Reply With Quote
Old 04-03-2011, 03:41 AM   #5 (permalink)
Registered Member
 
Join Date: Apr 2010
Location: Germany
Posts: 56
Applekuchen is on a distinguished road
Default

First of all, the concept of the game:
When you start the app, a main view is shown where you can choose one of three different game modes.
So, if the user plays in one game mode and gets a sms, the game should pause and if he cancels the notification, the game should go on.

1. Of course I can't but I have to put the code in my appDelegate, don't I?
the console says:

+[FirstViewController pauseGame]: unrecognized selector sent to class 0x1d39c
2011-04-03 10:32:48.025 theAppName[317:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[FirstViewController pauseGame]: unrecognized selector sent to class 0x1d39c'
terminate called after throwing an instance of 'NSException'
Applekuchen is offline   Reply With Quote
Old 04-03-2011, 05:02 PM   #6 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Is pauseGame a class method of FirstViewController or an instance method?
baja_yu is offline   Reply With Quote
Old 04-03-2011, 05:13 PM   #7 (permalink)
Registered Member
 
Join Date: Apr 2010
Location: Germany
Posts: 56
Applekuchen is on a distinguished road
Default

paueGame is an instance method of FirstViewController
Applekuchen is offline   Reply With Quote
Old 04-03-2011, 05:37 PM   #8 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

You're calling it as a class method.
baja_yu is offline   Reply With Quote
Old 04-04-2011, 11:29 AM   #9 (permalink)
Registered Member
 
Join Date: Apr 2010
Location: Germany
Posts: 56
Applekuchen is on a distinguished road
Default

how should I call it. can you give me an example, please?
Applekuchen is offline   Reply With Quote
Old 04-04-2011, 12:57 PM   #10 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

You need to have references to instances of those view controllers in your delegate to do that. Then call the methods on the instances, not the class. Instance variables are a good option.
baja_yu is offline   Reply With Quote
Old 04-04-2011, 04:50 PM   #11 (permalink)
Registered Member
 
Join Date: Apr 2010
Location: Germany
Posts: 56
Applekuchen is on a distinguished road
Default

what do you mean with references?
should I import the viewController like #import "FirstViewController.h" in my AppDelegate and then call the pauseGame method like [self pauseGame] ?
Applekuchen is offline   Reply With Quote
Old 04-04-2011, 07:05 PM   #12 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

You need pointers to actual objects of those view controllers classes to send the pauseGame message to.
baja_yu is offline   Reply With Quote
Reply

Bookmarks

Tags
crash, iphone sdk 4.2, objective-c, pause

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 372
12 members and 360 guests
condor304, dansparrow, dre, ilmman, LezB44, michelle, Objective Zero, samdanielblr, Sami Gh, shagor012, thephotographer, tinamm64
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:39 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0