5

I've tried several techniques to capture a screenshot of an app from within that app. None of the techniques appear to capture the status bar -- it ends up being black.

There apparently was once a way to do this, but that interface is internal and Apple will not let you use it.

Any ideas?

Note: This is an attempt to solve this problem, where I need to determine if airplane mode is on or off (and no, simply knowing if the network is reachable is not sufficient).

However, it would seem that this question is of more general interest, and is distinct from that question.

Community
  • 1
  • 1
Hot Licks
  • 44,830
  • 15
  • 88
  • 146
  • do you really need the status bar? Because you could just hide it and take a screenshot, in this case the screenshot should be complete(I might be wrong, never done it before) – Novarg Apr 03 '12 at 16:34
  • Yes, I need the status bar. That's what I'm trying to get an image of. – Hot Licks Apr 03 '12 at 16:36
  • Why not just ask the user to do it? – CodaFi Apr 03 '12 at 16:43
  • 7
    Because (sigh) I need to capture the status bar so I can look at it and see if airplane mode is enabled, since there's no other way to do that. And I need to do that to warn the user to enable airplane mode if operating on a second generation iPod Touch, since otherwise the WIFI generated audio noise when recording. – Hot Licks Apr 03 '12 at 16:47
  • @HotLicks wow..what a strange solution! – Mat Apr 03 '12 at 16:52
  • 2
    +1 for thinking so far outside the box to find out the status of airplane mode. +more if you list the other solutions you've tried to capture the screen – codeperson Apr 03 '12 at 16:56
  • I have found [code](http://bbs.51pda.cn/simple/?t4861.html) to detect airplane mode and turn it on and off. It seems very hacker-Like to me, but it is legal. – CodaFi Apr 03 '12 at 16:57
  • 3
    So all you _actually_ care about is no possibility of network activity; why not check the "reachability"? `SCNetworkReachabilityGetFlags()` – jscs Apr 03 '12 at 17:03
  • @jonsibley -- That interface is now located in "PrivateFramework" and presumably off-limits. – Hot Licks Apr 03 '12 at 17:19
  • 1
    @IuliusCæsar -- I need to have WIFI ***OFF***, not simply unreachable. – Hot Licks Apr 03 '12 at 17:20
  • 1
    To help people searching with similar problems in mind, please update your question to indicate the actual problem (determining WiFi state.) – Jonathan Grynspan Apr 03 '12 at 19:57
  • @JonathanGrynspan -- I've got a separate thread open for that: http://stackoverflow.com/questions/9981427/airplane-mode-on-ipod-touch-revisited – Hot Licks Apr 03 '12 at 20:03
  • You should not open duplicate questions. Update the existing one instead of spreading it out. – Jonathan Grynspan Apr 03 '12 at 20:21
  • @JonathanGrynspan -- You should also not change the topic of a question. – Hot Licks Apr 03 '12 at 20:37
  • I haven't. :) I've updated the question for you with the information that's missing so that other users can find it. – Jonathan Grynspan Apr 03 '12 at 20:40
  • @HotLicks, you should delete your other question and incorporate the information from it here. At this point it's become a networking question, not a screenshot one. – benzado Apr 03 '12 at 21:27
  • @benzado -- Kinda pointless, as it turns out there's no answer to either question. – Hot Licks Apr 03 '12 at 21:32
  • @HotLicks Stack Overflow isn't a discussion forum, it's about building a useful Q&A repository, so no, not pointless. – benzado Apr 03 '12 at 21:34
  • possible duplicate of [How to take a screenshot programmatically](http://stackoverflow.com/questions/2200736/how-to-take-a-screenshot-programmatically) – bjb568 Jul 28 '14 at 02:50
  • Pretty sure the above is not a dupe, since it doesn't capture the *entire* screen (including the header), as I was seeking to do. – Hot Licks Jul 28 '14 at 03:31

5 Answers5

6

Your actual issue, determining if a network interface is active, can be resolved with BSD networking functions. BEHOLD.

#include <sys/socket.h>
#include <ifaddrs.h>
#include <net/if.h>

BOOL IsNICTurnedOn(const char *nicName) {
    BOOL result = NO;

    struct ifaddrs *addrs = NULL;
    if (0 == getifaddrs(&addrs)) {
        for (struct ifaddrs *addr = addrs; addr != NULL; addr = addr->ifa_next) {
            if (0 == strcmp(addr->ifa_name, nicName)) {
                result = (0 != (addr->ifa_flags & (IFF_UP | IFF_RUNNING)));
                break;
            }
        }
        freeifaddrs(addrs);
    }

    return result;
}

To use this function:

BOOL isWWANEnabled = IsNICTurnedOn("pdp_ip0");
BOOL isWiFiEnabled = IsNICTurnedOn("en0");
Jonathan Grynspan
  • 42,652
  • 8
  • 68
  • 102
2

At this point it seems clear that there is no simple way to detect if Airplane Mode is enabled. Although you could probably infer it by looking at low-level network stack info or scraping status bar pixels, either method would be relying on undocumented behavior. It's very possible that on a future release of iOS or a future iOS device, the behavior will change and your code will generate a false positive or false negative.

(Not to mention that, on future devices, the interference may not even be there.)

If I were in your shoes, I would:

  1. File a bug to let Apple know you want this feature.

  2. Work the notice into the app, regardless of whether Airplane Mode is enabled. Yes, it might be kind of annoying to the user if it is enabled, but the overall harm is minimal. I would probably make this an alert that pops up only once (storing a key in NSUserDefaults to indicate whether its already been displayed).

  3. If you want to get super-fancy, analyze the recorded audio and, if the buzz is detected, remind the user again to enable Airplane Mode while recording. You could do this in real time or after the clip has been recorded, whatever makes more sense for your app.

benzado
  • 74,658
  • 20
  • 105
  • 133
0

Kind of a different approach, but you can also link to pages within the Settings application. You could perhaps link to the primary page and tell the user the changes you require.

Sam
  • 2,539
  • 15
  • 27
0

There appears to be no way to do this.

Hot Licks
  • 44,830
  • 15
  • 88
  • 146
0

As an alternative solution, perhaps you could detect the connection type, similar to: https://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html . With some additional checking for the device type, you could then warn the user only in the case where they need to act.

strings42
  • 533
  • 3
  • 9