AdColony ad restarting app - ios

I am currently making an iOS game using sprite kit. In one of my SKScenes, my store scene, the user can watch an AdColony ad. The ad plays fine, but after it is finished, the store scene is deallocated and the app returns to the menu screen. Why is this happening, and how can I return to the store scene without deallocating it?
Edit: Here's my code
//User taps a button (really a skspritenode)
//UIAlertView pops up asking them to watch a video
alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
//User tapped button 1 (aka agreed to watch video)
if (buttonIndex == 1){
//Present video
[AdColony playVideoAdForZone:#"xxxxxxxxxxxxxxxxxxxx" withDelegate:self];
}];
}

Related

adMob iOS resume (back to app button)

I have a little game with a timer.
I'm implementing adMob to monetize and I am not able to restart timer/ads after user clicks on the banner and come back to the app.
The flow is:
1 - game start
2 - show ads
3 - click on banner and pause timer
4 - oper safari
5 - click "back to my app" link/button (iOS feature)
6 - back to the app and restar timer (problem here)
I had implemented all adMob events method (and insert restar timer code) but I can't get out of this issue.
The code work because it worked with iAds (I'm migrating to adMob).
Any help is appreciated.
Thank you
EDIT:
here is the code:
/// Tells the delegate an ad request loaded an ad.
- (void)adViewDidReceiveAd:(GADBannerView *)adView {
NSLog(#"adViewDidReceiveAd");
self.pauseTimer = NO;
}
/// Tells the delegate an ad request failed.
- (void)adView:(GADBannerView *)adView
didFailToReceiveAdWithError:(GADRequestError *)error {
NSLog(#"adView:didFailToReceiveAdWithError: %#", [error localizedDescription]);
self.pauseTimer = NO;
}
/// Tells the delegate that a full screen view will be presented in response
/// to the user clicking on an ad.
- (void)adViewWillPresentScreen:(GADBannerView *)adView {
NSLog(#"adViewWillPresentScreen");
self.pauseTimer = NO;
}
/// Tells the delegate that the full screen view will be dismissed.
- (void)adViewWillDismissScreen:(GADBannerView *)adView {
NSLog(#"adViewWillDismissScreen");
self.pauseTimer = NO;
}
/// Tells the delegate that the full screen view has been dismissed.
- (void)adViewDidDismissScreen:(GADBannerView *)adView {
NSLog(#"adViewDidDismissScreen");
self.pauseTimer = NO;
}
/// Tells the delegate that a user click will open another app (such as
/// the App Store), backgrounding the current app.
- (void)adViewWillLeaveApplication:(GADBannerView *)adView {
NSLog(#"adViewWillLeaveApplication");
self.pauseTimer = YES;
}
In this VC create a property to store this
#property (nonatomic) BOOL didGoToSafari;
- (void)adViewWillLeaveApplication:(GADBannerView *)adView {
NSLog(#"adViewWillLeaveApplication");
self.pauseTimer = YES;
self.didGoToSafari = YES;
}
In the VC that you show right before the ad would show in viewWillAppear or viewDidAppear you should put this code
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(applicationDidBecomeActiveNotification:)
name:UIApplicationDidBecomeActiveNotification
object:[UIApplication sharedApplication]];
And then after viewDidAppear or viewWillAppear, write this function
- (void)applicationDidBecomeActiveNotification:(NSNotification *)notification {
if (self.didGoToSafari = YES){
self.pauseTimer = NO;
self.didGoToSafari = NO;
}
}
In viewWillDisappear
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification
object:[UIApplication sharedApplication]];
Basically what you're doing is listening to see if the app became active again. If it did, check to see if it's coming back from Safari. It's not perfect because you could feasibly be using the app, user goes to Safari and then doesn't go back to or close the game. They could then use Safari later and then go back to the game and it would start running again. There probably some control flow in the AppDelegate you could use to code around this, but in general this code should do it.
EDIT: As per your comment about understanding it, here's the full explanation.
You are using NSNotification to listen for when the app returns to an active state. UIApplicationDidBecomeActiveNotification is automatically called when your app becomes active (it's an app delegate method). When it does, the method (void)applicationDidBecomeActiveNotification gets called automatically and the methods in that method get called. You have a boolean flag to see if the app is returning from Safari because your app could return from any other app if user switched to another app when the ad got pushed. In the end, you remove your VC as an observer to avoid memory leaks.

When is Game Center Welcome Back banner firing?

My iOS game is using Game Center.
I am authenticating via the following code:
GKLocalPlayer* localPlayer = [GKLocalPlayer localPlayer];
localPlayer.authenticateHandler = ^(UIViewController* viewController, NSError* error) {
if (viewController != nil) { [self.window.rootViewController presentViewController:viewController animated:YES completion:nil]; }
else {
if ([GKLocalPlayer localPlayer].authenticated) {
// code for Game Center enabled
[[GKLocalPlayer localPlayer] loadDefaultLeaderboardIdentifierWithCompletionHandler:getLeaderboardIdentifier]; }
else {
// code for Game Center disabled
}
} // viewController was nil
}; // localPlayer.authenticateHandler
It all works well, but when the game has been in the background for some time and gets restarted, the annoying "welcome back banner" is displayed even though I am not calling the previous code as I have checked that ([GKLocalPlayer localPlayer].authenticated == YES)...
Is there a way to know if this banner is going to appear that I could use in applicationWillEnterForeground?
At worse, is there a known background delay that triggers it?
In this case I would slightly delay resuming into the game for a better UX...
As there does not seem to be a way to know in advance for sure if the "Welcome Back" banner is going to be displayed when localPlayer is already authenticated, I will for now stick with the background delay trick.
I have done a dichotomic test by playing the game, leaving the App in the background and returning to the App after delay D.
It seems that the "Welcome Back" banner does not appear if D < 8 minutes and does if D is greater. If that may help others in improving their user experience...
In my case, if D >= 8 minutes when applicationWillEnterForeground, I disable the resume game button for 2.5 seconds. Most of the time, the "Welcome Back" banner appears during that lapse and doesn't bother the user while a tough game is restarting.

Banner covers UIActionSheet in Swift

I have a RevMob banner in Swift, its working perfectly but when opening an UIActionSheet the cancel button gets covered by the advertisement, this also happens with GameCenter , what should I do to fix it?
My code:
func appearAd(){
if revMobSession == true{
RevMobAds.session().showBanner()
}
}

how to detect microphone permission pop up

I have an animating sine wave in my app that needs to be reset when the user hits the home button or locks their phone (turning off the screen). Once the user brings the app back to the foreground, the sine wave animation is triggered again. This works fine until I realized it was occurring when the microphone access permission pops up. So the microphone access pops up, causing my app to go into the background and the animation to turn off, but the app is still visible. Any way I can know that the mic access pop up is occurring, so I can make some kind of if statement?
-(void) appDidEnterForeground:(NSNotification *)notification
{
if( viewIsUp == NO)
{
[self.sineWave.layer removeAllAnimations];
}
else
{
[self.sineWave animateWave];
}
}
-(void) appDidEnterBackground:(NSNotification *)notification
{
if(viewIsUp)
{
[self.sineWave.layer removeAllAnimations];
}
}
I accidentally set UIApplicationWillResignActiveNotification as the notification to call appDidEnterBackground. When the microphone access pop up would display, the only notification that would get called was UIApplicationWillResignActiveNotification. So when the home button was tapped or the screen was locked, I would remove the animation when UIApplicationDidEnterBackgroundNotification was called and when the mic access pop up displayed, I would leave the animation as it is when UIApplicationWillResignActiveNotification gets called. Worked out nicely. Hope this helps someone.

Can I manually prompt the user to log in to Game Center on iOS 7?

According to Apple's Game Center programming guide, this code sets up an authentication handler. If you run this at the beginning of your game, the first time you run it, it will prompt the user to log in if they haven't yet.
- (void)authenticateLocalPlayer {
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error){
if (viewController != nil) {
NSLog(#"Player not authenticated.");
} else if (localPlayer.isAuthenticated) {
NSLog(#"Authentication successful.");
} else {
NSLog(#"Authentication failed. Error: %#.",error);
}
};
}
Suppose that the user hasn't logged in yet, and cancels the authentication screen to play the game normally.
There is a button for playing a multiplayer match in my game. If the user presses the button, it will attempt to search for other players by presenting a GKMatchmakerViewController instance.
Since the player isn't logged in, the player will actually receive an error dialog saying that they aren't logged in. The dialog only has an OK button, which dismisses it.
If the player insists on pressing this button, the same dialog will come.
However, this is an odd behaviour. It would be more reasonable that if the player wants to play a multiplayer match but isn't logged in yet, the game will prompt the user to log in.
The above code sets up a handler, so it really isn't what I'm looking for. However, I made a breakpoint and noticed that viewController is a GKHostedAuthenticateViewController instance. I figured that maybe I could create an instance of that class and present it, which should technically be equivalent to prompting the user to log in.
However, Xcode doesn't seem to recognise that class when I write it. I'm under the impression that I'm not allowed to do this.
How can I manually prompt the user to log in to Game Center?
You can first check if the player is authenticated or not, by reading the GKLocalPlayer object.
If there is not authenticated user, you can open the game centre app. The downside with this method is that after the user authenticates through the game centre app, he is still in the game centre app and has to "switch back" to your app. When he switches back, the authentication handler you defined in your code gets triggered.
-(void)clickedOnStartGame
{
if (_signedIn)
{
//Do what you need to.
}
else if (!_signedIn)
{
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Game Center"
message:#"If Game Center is disabled try logging in through the Game Center app"
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:#"Open Game Center", nil];
[alertView show];
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"gamecenter:"]];
}
}
EDIT: Note, that in Apple's documentation, they say that you shouldn't be prompting the user to log in again, or show a login prompt. The automated way, (which your code already has) is supposed to be the accepted way. Showing the alert view I described above just helps the user log into game centre since you aren't supposed to force the app to show a dialogue.

Resources