iOS 5.1 Stops app when in background - objective-c

I have a published (Cocos2d+UIKit)app in the store, which reproduces audio tracks and needs to keep playing them even if the iPhone is locked or the app is in background.
It used to work perfectly well until iOS 5.0 but since iOS 5.1 the app is restarted: sound stops, when user unlocks iPhone doesn't appear active, when opening again it shows the splash screen and initial window.
I tried to debug it but when I lock the iPhone, xCode gets paused in EAGL...
I also tried to play the tracks in a MPMoviePlayerViewController and it does the same.
Please help, I am getting many bad reviews every day due to this issue...

It is hard to tell without seeing your code, but as a wild guess, try this line:
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
Put in your first controller's viewDidLoad method. Let me know if it fixes the problem for you.
------ Update -----
An additional thing to check for 5.1 is to set
[[AVAudioSession sharedInstance] setActive: YES error: nil];
before each AVAudioPlayer play command.
This solved it for my alarm clock app which used to sound at the alarm time perfectly in 4.x and started to get muted in 5.1. I found that the putting the above line before [AVAudioPlayer play] solved the problem for me.

Think I finally solved it by adding:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[[CCDirector sharedDirector] stopAnimation];
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[[CCDirector sharedDirector] startAnimation];
[Appirater appEnteredForeground:YES];
}
- (void)applicationWillResignActive:(UIApplication *)application
{
[[CCDirector sharedDirector] pause];
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
[[CCDirector sharedDirector] resume];
}
I am not sure why it was working fine before iOS 5.1, but that fixed it :)

Related

iPad iOS 9 having issue in display keyboard when select textfield

My app is iPhone based app , while running my application in iPad device
I select the UITextField, It takes 10 to 20 secs to display the keyboard for the first time in the iPad device alone,but later it working fine in displaying keyboard, Its a strange thing,
Please help me to get rid of this problem
This worked for me.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Preloads keyboard so there's no lag on initial keyboard appearance.
UITextField *lagFreeField = [[UITextField alloc] init];
[self.window addSubview:lagFreeField];
[lagFreeField becomeFirstResponder];
[lagFreeField resignFirstResponder];
[lagFreeField removeFromSuperview];
}
Taken from this stack overflow answer: Super slow lag/delay on initial keyboard animation of UITextField

Push Notifications Stopped working iOS8 beta

So this just adds to the numerous issues i've had with the latest iOS8 beta update. My app was working fine using parse to send push notifications. It was working great on my phone and on the iOS7 simulators. However now I'm not receiving the notifications at all. Parse is saying my phone is still registered which it is. The console is giving me the error "registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later." Which is understandable however I believe my code solves that issue and until this update it was. I noticed as well when running the simulator that if my app is deleted from it and then I run the program again in the simulator. No dialog box is appearing asking if I want to accept push notifications, instead it is automatically setting it so they are accepted, it's doing it on my phone as well. As a side note this could potentially be a bug with the update as my other push notifications have been late/random today from other apps. However I would appreciate someone looking over the code to check please.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:252/255.0f green:230/255.0f blue:17.0/255.0f alpha:1.0]];
[[UIToolbar appearance] setBarTintColor:[UIColor colorWithRed:252/255.0f green:230/255.0f blue:17.0/255.0f alpha:1.0]];
[Parse setApplicationId:#"***"
clientKey:#"***"];
// Register for push notifications
[application registerForRemoteNotificationTypes:
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound];
#ifdef __IPHONE_8_0
//Right, that is the point
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge
|UIRemoteNotificationTypeSound
|UIRemoteNotificationTypeAlert) categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
#else
//register to receive notifications
UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];
#endif
return YES;
}
#ifdef __IPHONE_8_0
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
//register to receive notifications
[application registerForRemoteNotifications];
}
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler
{
//handle the actions
if ([identifier isEqualToString:#"declineAction"]){
}
else if ([identifier isEqualToString:#"answerAction"]){
}
}
#endif
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)newDeviceToken {
// Store the deviceToken in the current installation and save it to Parse.
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:newDeviceToken];
[currentInstallation saveInBackground];
}
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo {
[PFPush handlePush:userInfo];
}
UPDATE: I created a new app in Parse and copied the application IDs etc into it (missing the certificates stage of setting it up as they won't change right?) And now even though the app says in settings that it is registered to receive notifications, again without asking) Parse says that it is not.
Don't know how or why? But the pushes have started working again. Haven't changed any of the settings from what is above so if anyone is looking for a solution to using parse this works apparently!
For iOS8 to receive push notification take a look on this :
Not able to set Interactive Push Notifications on iOS8
The push notification is working and appearing, but the interactive buttons aren't working.
I think there's something related to the category..
If any one found something please update.

Unable to detect iPhone Retina 4-inch screen size in simulator

I want to make my iOS application support iPhone 5. So I created a separate xib set for iPhone 5 size. Then I load each xib by checking the screen height.
This is the splash screen loading code inside the AppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
UIViewController *viewController1;
if ([UIScreen mainScreen].bounds.size.height==480) {
viewController1 = [[SplashScreen alloc] initWithNibName:#"SplashScreen" bundle:nil];
}
if ([UIScreen mainScreen].bounds.size.height==568) {
viewController1 = [[SplashScreen alloc] initWithNibName:#"SplashScreen5" bundle:nil];
}
self.window.rootViewController = viewController1;
[self.window makeKeyAndVisible];
return YES;
}
But when I change the simulator into Retina 4-inch, my code doesn't get the emulator size. It always executes the 480 if condition.
But other apps I created like this are working properly.
What is the reason for this?
I'm having the exact same problem right now (at the worst moment, of course....).
It did work properly for several weeks, and for a unknown reason, the simulator suddenly considers the 4in simulated device as a 3.5in screen.
cleaning, reset, reboot : same situation...
EDIT : ok, problem solved. T'was because of a missing Default image in the -568#2x format. I knew that was a condition to make the system work, but xcode had apparently decided to get rid off the one I chose. oh well...

UISwipeGestureRecognizer works for touches 1 and 2 but not 3

The following does not work — handleSwipeUpTriple is never called:
- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UISwipeGestureRecognizer *swipeUpTripleRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipeUpTriple:)];
swipeUpTripleRecognizer.direction = UISwipeGestureRecognizerDirectionUp;
swipeUpTripleRecognizer.numberOfTouchesRequired = 3; // triple finger
// window is in nib
[self.window addGestureRecognizer:swipeUpTripleRecognizer];
[swipeUpTripleRecognizer release];
}
- (void) handleSwipeUpTriple:(UISwipeGestureRecognizer *)sender {
printf("\nhandleSwipUpTrpl called."); // never happens
if (sender.state == UIGestureRecognizerStateEnded)
printf("\n SwipeUpTriple recognized.");
}
}
The weird thing is that if I change the numberOfTouchesRequired to 1 or even 2, it works. Only 3 (or 4) fingers seem to be out of bounds. Since I see a number of posts regarding 3-finger gestures, I don’t see why this should be.
self.window.multipleTouchEnabled is YES.
For testing purposes, I have removed all subviews. There’s nothing but self.window on the screen.
I’m still using iOS 4.3, but since UISwipeGestureRecognizer was available by iOS 3.2, I don’t see why that should be a problem.
I know that the non-iPad devices sometimes are running system gesture recognizers for 3 fingers (usually zoom). Depending on your settings the system may have reserved this number of fingers for itself.
As we found, you can fix this by going to General > Accessibility and disabling the three-finger gestures.

UIImagePickerController crash on iOS 5

UIImagePickerController *ii_picker= [[UIImagePickerController alloc] init];
ii_picker.delegate=self;
ii_picker.sourceType=UIImagePickerControllerSourceTypeCamera;
add_photo=NO;
[self presentModalViewController:ii_picker animated:YES];
[ii_picker release];
This used to work fine till I updated to iOS 5 on my iPhone. Something strange...
Problem isn't in the code. It's working in blank project! If I paste it to any place in my project's code, it's crashing. If I change UIImagePickerControllerSourceTypeCamera to UIImagePickerControllerSourceTypeSavedPhotosAlbum, it's working in iOS5.
Does anybody know where the problem is?
If app is crashes in iOS 5 , then try to use
[self dismissModalViewControllerAnimated:YES];
picker = nil ;
In place of
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
[picker release];
If your app crashes as below, need to change the app's product name in English.
In my case product name was written in Korean, this led to the crash in ios5 when UIImagePickerController's source type is UIImagePickerControllerSourceTypeCamera.
Note, on the simulator, there's no camera, so it could cause this.