iAd giving problems with Shaking Motion - iphone

I have an application that needs to detect a shaking motion to start/restart its activity. It is already on-Line, but now I want to add the new feature of iAd. I've implemented all the needed methods, but I have a problem: when I enter the Ad and then exit, the device can't catch the shaking motion anymore.
Ideas? Hint.
Thank you.

In the below stackoverflow link:- How to use Shake API in iPhone SDK 3.0?
detailed info is provided. check this.
hope it helps

Solved, actually I get the problem reading diggin into answers linked by Srinivas.
The problem was that when the Ad is end and returns back the control to my UIViewController, this one is no more the First Responder setted on his view. The solution:
- (void)bannerViewActionDidFinish:(ADBannerView *)banner {
[[self view] becomeFirstResponder];
}
Nothing more.

Related

cut/copy/paste functionality stopped working in my iOS application

UPDATE: cut/copy/paste disabled in my app.
I am confused with my iOS app while developing for iPhone devices. Execution flow enters a point like the code below
[self navigationController] pushViewController:chooseDeviceView animated:YES];
[chooseDeviceView release];
[numberTextField setText:#""];
The view changes and things "work properly". The problem is that after this the cut/copy/paste functionality is missing in my app.
Don't really know how to start debugging the issue. Does it ring a bell to anybody?
That was a very complicated issue for a beginner. Finally the issue was a little bit related with status message corrupts main window in my iPhone app
Add in your new viewController this:
- (BOOL)canBecomeFirstResponder {
return YES;
}
It should solve your issue.

iAd Doesn't Animate Ad Appearance

I'm implementing iAd in my app using the paradigms for a multi-VC app that apple demonstrates in their sample code (e.g. TabbedBanner and NavigationBanner). If you're not familiar with it, the paradigm is essentially to have the main app delegate serve as the primary AdBannerViewDelegate, and share the banner view across your respective view controllers.
My ads are appearing fine throughout the app, without any warnings. The problem is that for some reason when I click an ad banner, it doesn't navigate the appearance of the ad (should slide up from the bottom). There's just a delay and then the ad appears. But when I dismiss the ad it animates fine.
The appearance animates fine in apple's sample code, so the problem lies somewhere in my code. I'm just not sure where because I haven't changed much in the iAd implementation. My bannerViewActionShouldBegin is just
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{
[[NSNotificationCenter defaultCenter] postNotificationName:BannerViewActionWillBegin object:self];
return YES;
}
But I don't think the problem lies in the NotificationCenter, because if I comment out that bit and just do
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{
return YES;
}
The problem remains.
Any ideas? I can post more code, but my digging around in the documentation hasn't revealed anything that would flip an animated BOOL for ad presentation.
Thanks in advance.
FWIW, the best I could figure is that this seems to simply be an iOS version issue. In 4.0 it fails to animate. In 5.0 it animates.

Cocos2d fails on iPad yet works in simulator

I have a very simple game using Xcode v4.2.1, Cocos2d v5.0.1. I've tried both compilers in Xcode (LLVM GCC 4.2 and Apple LLVM compiler 3.0. Is there a preference??) On the game screen is a UIKit button that presents the user with a Interface Builder (nib) Settings/Options screen to customize the game a bit. This is all based on what I learned in Ray Wenderlich's tutorial (http://www.raywenderlich.com/4817/how-to-integrate-cocos2d-and-uikit).
After the user makes their changes, they are returned to the game and the changes are in place.
This all works as I want in the simulator, however, when I test the game on an iPad I get the following errors in the debug window:
2012-01-27 18:25:27.305 BonkBonk[1082:707] failed to call context
2012-01-27 18:25:27.310 BonkBonk[1082:707] cocos2d: surface size: 1024x768
2012-01-27 18:25:27.316 BonkBonk[1082:707] Failed to make complete framebuffer object 8cdd
OpenGL error 0x0506 in -[EAGLView swapBuffers]
OpenGL error 0x0506 in -[EAGLView swapBuffers]
OpenGL error 0x0506 in -[EAGLView swapBuffers]
The OpeenGl errors continue on indefinitely.
I use the function viewWillAppear to capture the return from the settings/options screen so that I can pass the new settings to the game layer. If I comment out this code the problem goes away, however, I am not able to get the new user settings to the game layer.
Here is the code:
- (void) viewWillAppear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:YES animated:animated];
//CCScene *scene = [[CCDirector sharedDirector] runningScene];
CCScene *scene = [BonkBonkLayer scene];
id layer = [scene getChildByTag:1];
[layer userSettings];
[super viewWillAppear:animated];
}
The commented out line //CCSene *scene... was another failed attempt at getting the layer object from the scene so that I could call the userSettings method where the game layer then can assimilate it into the game.
OK, so I've found something that alleviates my issue.
If anyone knows anything about this, please let me know. I will continue to use this fix unless I hear a reason from someone more knowledgable than myself (and that's not that difficult).
The solution is found in the comment by "psionic" at the end of the following discussion:
http://www.cocos2d-iphone.org/forum/topic/7068.
Basically, I created a static bool in the EAGLView class (EAGLView.m) that surrounds the call to _resizeFromLayer in the layoutSubViews member function. The call to _resizeFromLayer is only called the first time through, and then never again.
Please read the above discussion and let me know what you like/dislike about this solution, other than the obvious... it's a hack.
A hack,that works. I think.
I had a similar problem. I've integrated cocos2d with UIKit. I added adMob. The problem shows up when user clicks on Ads that presents the google BrowserView. If you dismiss the View using the Done button, the App works fine. However, if user press the Home button when in Browser View, and resume the App, I got the same exception.
OpenGL error 0x0506 in -[EAGLView swapBuffers]
UIKit buttons and the Ads are shown, but it does not render the cocos2d layer.
I got the solution from https://github.com/cocos2d/cocos2d-iphone/pull/198, but I did not change the cocos2d source. Instead, I added a boolean ivar called isAnimating in AppDelegate.m, and expose the property to the Layers.
To solve this, I stop animation on CCDirector before entering google Browser View. and start animation once resume to the App. isAnimating ivar is used to check that start animation is not called twice.
Hope it helps,
I had similar errors in my app when implementing Cocos2D via CCGLView.
The solution that worked for me was to call
[[CCDirector sharedDirector] popScene]
when presenting the Interface Builder Viewcontroller.

iPad rotation bug when using MPMoviePlayerViewController

Issue summary
Changing the orientation of an iPad device or simulator while playing a video using MPMoviePlayerViewController results in an inconsistent rotation state upon dismissal of the video player. This is a known bug in iPad SDK 3.2, documented at http://www.openradar.me/8012810
Sample project
I have prepared a minimal sample project using the View-based Application template from Xcode 3.2.2, using the following code to launch the player
NSURL *movieUrl = [NSURL URLWithString:#"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"];
MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc] initWithContentURL:movieUrl];
[self presentMoviePlayerViewControllerAnimated:player];
[player release];
The code is available on GitHub at http://github.com/adamalex/FullScreenMovie or direct download using http://github.com/adamalex/FullScreenMovie/zipball/master
Steps to reproduce
Obtain the project using the information above
Launch the project with the iPad simulator or device
Tap the button to begin playing the video
Rotate the iPad by 90 degrees
Dismiss the video
Note the UIStatusBar is out of sync with the application UI
Objective
I have contacted Apple and they have confirmed this is a bug that is being investigated. I would like to discuss temporary workarounds that use public APIs safe for submission to the App Store. I am going to open a developer support case with Apple as well and will report back with my own progress.
Successful response from Apple Developer Technical Support!
This is a known bug and a we're received a number of duplicate bug reports and so iOS engineering is aware of the issue and we do have a temporary workaround as suggested by iOS engineering.
You will need to implement this in the view controller which presents the movie player.
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
[self performSelector:#selector(fixStatusBar) withObject:nil afterDelay:0];
}
- (void)fixStatusBar {
[[UIApplication sharedApplication] setStatusBarOrientation:[self interfaceOrientation] animated:NO];
}
While this is somewhat ugly, it should fix the issue for now. It would be recommended to remove this code once the bug is fixed in the system.
This took care of the issue completely for me, and you can revisit http://github.com/adamalex/FullScreenMovie for the code with the fix applied.
This also solves an iPhone/iPodTouch rotation issue that I was struggling with. I am developing a universal app in which each view displays a different image depending on whether the device is in portrait or landscape orientation. Buttons are used to navigate between views.
If the app is running on the device and a portrait view is rotated to landscape, my image switching takes place. If the device is then placed flat on a table top and the button is tapped to display the next view, the view appears in landscape but shows the portrait image instead. I solved the problem by forcing a portrait view to appear by detecting for face up and down, but Apple's code solved this problem (as well as the similar movie problem I was also experiencing).
Many thanks for reporting the bug - I assumed it was just my bad coding...

Problem with applicationShouldTerminate on iPhone

I'm having a problem with applicationShouldTerminate.
What ever I do it seams that has no effect. Any help would be
appreciated.
I'm well versed in programing but this just gives me headache. Im going
over some basic tutorials for xcode , as I'm new to mac in general, and am currently looking at a simple flashlight app.
It exists but I would like to add a alert box here with option not to
quit.
(void)applicationWillTerminate:(UIApplication *)application
{
[application setIdleTimerDisabled:NO];
}
this has no effect, alert is closed even before its created.
(void)applicationWillTerminate:(UIApplication *)application
{
[application setIdleTimerDisabled:NO];
UIAlertView *alertTest = [[UIAlertView alloc]
initWithTitle:#"This is a Test"
message:#"This is the message contained
with a UIAlertView"
delegate:self
cancelButtonTitle:#"Button #1"
otherButtonTitles:nil];
[alertTest addButtonWithTitle:#"Button #2"];
[alertTest show];
[alertTest autorelease];
NSLog(#"Termination");
}
I did some reading online and found that it should be possible to do
this with
(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender
But no mater where I put that declaration I get error: syntax error
before NSApplicationTerminateReply.
There is no syntax error except that xcode seems not to recognize
NSApplicationTerminateReply as valid input.
Any sample code would be greatly appreciated.
I know this is a non-answer, but hopefully I can be helpful:
Displaying a "Really quit?"-type alert like this, even if you can pull it off technically (and I'm not sure you can), is a bad idea and is likely to either cause rejection from the App Store or, at best, an inconsistent user experience because no other apps do this.
The convention with iPhone apps is to save state if necessary, then yield control (for termination) as quickly as possible when the user hits the home button or switches apps.
To ensure a consistent experience, Apple probably has an aggressive timer in place to restrict what you can do in applicationWillTerminate. And even if they don't have a technical measure in place, they probably have an App Store approval policy to ensure that applications quit immediately when they're asked to.
applicationShouldTerminate and NSApplication do not exist on the iPhone. You have to use UIApplication.
The alert view is never shown because the 'show' method does not block, and therefore, the end of 'applicationWillTerminate' is reached immediately after you create the alert view and try to show it. I believe this is by design. You can't really begin asynchronous operations in 'applicationWillTerminate'.
With regards to the applicationShouldTerminate error, in case anyone's curious, NSApplicationTerminateReply and NSApplication seem to be deprecated...even though the OP's method is exactly how it appears in the docs!
Defining your method as the below should build with no errors:
-(BOOL)applicationShouldTerminate :(UIApplication *)application
I think I found the answer to what I wanted to do but will need to check it when I get back home.
Some directions were found here
http://blog.minus-zero.org/
The iPhone 2.0 software was recently released, and with it came the
ability for users to download native apps (i.e., not web sites)
directly to their phones from within the iPhone UI or via iTunes.
Developers (anyone who pays Apple 59GBP for the privilege) can then
write their own apps and have them available for purchase in the App
Store.
One limitation of the Apple-sanctioned SDK is that only one
application is allowed to be running at a time. This presents a
problem for apps such as IM clients, music players and other programs
whose functionality relies on being able to run in the background.
Another example (courtesy of James) would be an app that takes
advantage of the iPhone 3G's GPS chip to create a log of all the
places you visit.
However, there is a neat trick that I discovered: your app will only
get terminated if you switch away from it, and hitting the iPhone's
power button while your app is in the foreground doesn't count as
switching away. The upshot of this is you can create apps which
continue to run while the iPhone is in your pocket - perfect for the
GPS example.
Achieving this is as simple as implementing two methods in your
UIApplication delegate - applicationWillResignActive: and
applicationDidBecomeActive:. Here's a simple example to demonstrate
the effect.
In your UIApplication delegate header file, add a new ivar: BOOL
activeApp. Then, in your implementation, add the following three
methods:
- (void)applicationWillResignActive:(UIApplication *)application {
NSLog(#"resigning active status...");
activeApp = NO;
[self performSelector:#selector(sayHello) withObject:nil afterDelay:1.0];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
NSLog(#"becoming the active app...");
activeApp = YES;
}
- (void)sayHello {
NSLog(#"Hello!");
if (!activeApp)
[self performSelector:#selector(sayHello) withObject:nil afterDelay:1.0];
}