0

My app supports both iOS 6 and iOS 7. I am using some methods that are available from iOS7 only (like suspend) but are not available in iOS6. However, i am using proper branching for iOS6 and iOS7 (putting conditions accordingly). However, i am getting warning when i am using the suspend method.

This is my method:

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
        UIApplication *app = [UIApplication sharedApplication];

    if([app respondsToSelector:@selector(suspend)])
    {
        [app performSelector:@selector(suspend)];

        [NSThread sleepForTimeInterval:1.0];
    }
        exit(0);
}

The warning is

"Undeclared Selector 'suspend'"
Shradha
  • 991
  • 3
  • 13
  • 38
  • Show the relevant code. – rmaddy Jan 29 '14 at 07:41
  • 1
    Check this **http://stackoverflow.com/questions/18404746/conditionally-hide-code-from-the-compiler?lq=1** – Kumar KL Jan 29 '14 at 07:43
  • suspend is avail for IOS 6 also . – Kumar KL Jan 29 '14 at 07:55
  • 1
    "suspend" is not a public method for UIApplication. The use of private API will get your app rejected on the store eventually, plus it would appear as if your app as crash. May I suggest NOT to provide an alert view with a exit button and let the user push the home button to go back to the Home Screen! – Florian Burel Jan 29 '14 at 08:07

4 Answers4

3

There are several things wrong with the code you posted.

  1. There is no public method named suspend for UIApplication. You appear to be attempting to call a private API. The compiler complains because it can't find a method named suspend (because there isn't a public one to be found). And as a side note, this will most likely result in your app being rejected by Apple.

  2. NEVER sleep on the main thread. Very bad.

  3. Never call exit. It's not allowed.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • So what is the alternative way to achieve what i am doing in this part of the code? Actually, I don't want the user to run the app on iPodTouch. So i need to check if he is trying to run the app on it, and if yes, the i need to exit from the app immediately. – Shradha Jan 29 '14 at 08:00
  • Your app will be rejected by Apple if you try to prevent the app from running on the iPod touch. Why are you doing any of this code? – rmaddy Jan 29 '14 at 08:01
  • because this is the clients requirement.. he needs the app to run on iphone and iPad only.. and the "suspend" is present in NSURLSession class – Shradha Jan 29 '14 at 08:04
  • 1. Why would the client not want to run on the iPod touch? 2. You can't prevent an app from running on the iPod touch. Apple won't allow such a restriction. It's pointless. 3. What does any of this have to do with trying to call `suspend` and `exit`? – rmaddy Jan 29 '14 at 08:06
  • I think i took the wrong approach here.. what i wanted to do is: "as soon as the user tries to run the app on iPod Touch, show him an alert that the app cannot be run on this device, and then send the app in background and then exit from app". I used suspend to send the app in background and exit to exit from the app. – Shradha Jan 29 '14 at 08:08
  • So it is absolutely mandatory to let the app be installed on iPod Touch? I am already making a universal application. – Shradha Jan 29 '14 at 08:09
  • 1
    `suspend` is a private API - app will be rejected. Trying to prevent the user from using the app on the iPod touch - app will be rejected. There is NO reason (even if allowed) to prevent the iPod touch. Imagine a user with only an iPod touch pays for the app. Then when it runs the user sees your message. Let all of the 1-star reviews pile up. – rmaddy Jan 29 '14 at 08:12
2

As the discussion showed that what you really want to do is to prevent the user from installing the app on iPod touch, I'll add an answer to that question:

The way to stop the app from being installed on certain devices is to use the UIRequiredDeviceCapabilities in you app's plist.

According to this list it seems the magnetometer is as close as you'll get to a perfect solution. It is supported in all iPhones and iPads except iPad1 and it is not supported by any of the iPod touch iterations...

T. Benjamin Larsen
  • 6,373
  • 4
  • 22
  • 32
  • ok.. thanks.. but i need to support iPad 1 to.. so i guess i will not be able to use this key.. – Shradha Jan 29 '14 at 08:24
  • Well then you'll have the unpleasant job of informing your client that his requirements are not technically possible. You have my sympathy... ;-) – T. Benjamin Larsen Jan 29 '14 at 08:27
0

The warning is issued because none of the imported header file declare a method matching the selector 'suspend'.

suspend is a private API.

Florian Burel
  • 3,408
  • 1
  • 19
  • 20
0

You might be able to suppress the warning by creating a category definition of UIApplication and declare the suspend function, otherwise you can suppress it with a -warc flag, but you'll have to find the right warning name.

maybe like this:

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundefined-selector"
//your warning causing code here
#pragma diagnostic pop

-OOOOR-

Try this solution : How to get rid of the 'undeclared selector' warning

Community
  • 1
  • 1
Bryce Buchanan
  • 279
  • 1
  • 10