Get a screenshot while App is in background? (Private APIs allowed) - iphone

I am developing a monitoring application for the iPad. It already uses private frameworks to send artificial events and simulate user input, while my App is on the background and another App on the foreground.
Now my problem is, I need to get a screenshot of the iPad as an image programatically. I know the UIGetScreenImage method, and also rendering every view on the screen to get the image. However, UIGetScreenImage cannot be called from the background. (I get an error telling me that when I try it from the background) And I cannot render the views from another App, since I only know my App's views.
OPTION 1
I am able to simulate a click on the home and lock keys, for the iPad to generate a screenshot. Afterwards, I use private APIs to access this image from the photoalbum, using the [PLPhotoLibrary](https://github.com/nst/iOS-Runtime-Headers/blob/3686717e107fa36a990fac20c30da2da9a25b698/PrivateFrameworks/PhotoLibrary.framework/PLPhotoLibrary.h
), PLPhotoAlbum and PLPhoto.
id lib = [PLPhotoLibrary sharedPhotoLibrary];
id allPhotosAlbum = [lib allPhotosAlbum];
id contents = [lib albumContents];
id lastPhoto = [contents objectAtIndex:[contents count] -1];
UIImage *screenshot = [lastPhoto newFullSizeImage];
The only problem with this approach is that the screenshots will stack up ont he album, filling the iPad's memory. So either I need another way, or I need a way to delete this pictures. But, when I call the delete methods in the photo album and photo library, I get a "SQLITE error 8 [attempt to write to readonly database]
Any suggestions on how to achieve this screenshot thing in a better way would be appreciated.
I will not be uploading this App to the App store. It is for private use.

It used to be that you could capture a screen-shot of the entire device screen, from the foreground or the background, using IOSurface. Apple blocked that API in iOS 9. It's no longer possible without jail breaking your device, private API or not.

Jailbreaking your device is probably the only recourse, not that I recommend doing that.
However, Apple never intended for people, developer or not, to use their iPad in the manner you describe.

After massive testing and trying, I concluded that even with private APIs erasing the photos from the photo album is too much of a problem, maybe even impossible.
I ended up writing a script that simulates user inputs and erases the photos.

You can use following private API: [[UIWindow class] performSelector:#selector(createScreenIOSurface)];

Related

iOS - How to show hints for gestures for iOS app?

I have seen some apps where when you launch them for the first time after downloading (e.g. Chrome app on iPhone), it shows you a list of animated gestures on the screen, kind of giving you a tour of the app.
How do I build one something like that? And how does the app know to launch only for the first time after download and not since then? For the second question, I am guessing a "shown=TRUE" value can be saved inside a PList file and checking the value each time when the app finished launching. But I am more curious about the mechanism involved in creating a guided app tour.
You can use transparent and semi-transparent images with a UIImageView, so you can make up an image with arrows and notes and put over the whole screen. You could fade it out when the user taps.
To know if it's the first time running the app, you should use NSUserDefaults instead of a plist; it's much easier, and you should be app to find a quick tutorial on that fairly easily.
Also, you could check around on this site for controls like this one. I haven't used any of them myself, so I'm not sure how much they differ from a regular UIImageView. They look nice though.

iPhone/ iPad app development TV Out

HI,
I have just submitted my first application to iTunes for approval, however, there is one thing I really want to add to it ASAP.
I would like to code into an app that it can use the TV Out functions of both the iPhone and iPad? Ideally it would work in a similar way to how keynote works i.e. you see a bit more on the iPad itself than is projected on the TV, but even just mirroring the screen would be a step in the right direction.
I have searched all over for this and all I keep getting is about downloading jailbreaks for you iPhone to mirror the screen, which doesn't really help.
Thanks in advance,
If you just want to mirror, use my TVOutManager singleton. I've put up code to do this on github: https://github.com/robterrell/TVOutManager (Hmmm... I just noticed I haven't pushed the most recent code. I'll review and push new code asap.) I wrote up some detailed info about it at http://www.touchcentric.com/blog/archives/123 if you want to know the how's and why's.
Basically, just add the files to your project, and call:
[[TVOutManager sharedInstance] startTVOut];
If you want to do more than mirroring, read the docs on UIScreen. It's fairly trivial to create a UIWindow on the external screen (steal the bits from TVOutManager if you need to) and add subviews to it. This way you could have a Keynote-like controller on the device screen, while the main display is on the external display.
http://mattgemmell.com/2010/06/01/ipad-vga-output should get you started ...
Mirroring is not possible.
But to draw on an external display, just get the UIScreen object for the external display, then set the screen property of a UIWindow to it, (making sure to set the frame correctly etc) everything in that window should be drawn on the respective display.
Relative links:
developer.apple.com/library/ios/#documentation/uikit/reference/UIWindow_Class/UIWindowClassReference/UIWindowClassReference.html (look at screen property)
developer.apple.com/library/ios/#documentation/uikit/reference/UIScreen_Class/Reference/UIScreen.html (look at +screens)
(I don't have any reputation => can't post clickable links)
I think, you can't do this. You can only stream videos from iPod app.
But, if you have jailbreak on your device, try this (link) or take a look at this great YouTube video (link) showing exactly what you need.

Output iPad content to external display

I've heard it's possible to output content from an iPad app to an external display, but the app has to be prepared for this and there are serious limitations. Any pointers?
And also, can this be done for iPhone? Is it the same?
As little indicates, you'll need to create a new UIWindow and attach it to the UIScreen for the external display. This UIWindow will host the content to be presented on the external display, so you'll need to build a distinct view hierarchy for that, separate from your main application interface. You also will need to listen for the UIScreenDidConnectNotification and UIScreenDidDisconnectNotification notifications that inform your application when the external display has been attached and removed.
I demonstrate how to do this in the video for the iPad session of my class on iTunes U, for which the course notes can be viewed here.
Matt Gemmell also did a very nice writeup on this recently, which you can read here.
The key to implementing this feature is contained in the UISCreen class:
http://developer.apple.com/iphone/library/documentation/uikit/reference/UIScreen_Class/Reference/UIScreen.html#//apple_ref/occ/clm/UIScreen/screens
Basically, your app will use UIScreen to get access to the external display screen and then set it as the screen for a new UIWindow (your app will have two UIWindows). The app can then add a ViewController to the new UIWindow that represents the second screen and off you go.
UIWindow *externalWindow.screen = [[[UIScreen screens] lastObject] retain];
[externalWindow addSubview:externalViewController.view];
It's pretty simple, but will take a little experimenting to get it working. It's a pain in the butt to debug your app on the device, since the 30-pin connector will be required to connect to the display, so cannot also be used for debugging. Perhaps there is a pass thru cable for allowing debug + external display, but I haven't had a chance to look.
Limitations:
You should be able to output video-quality bit rates, as apple has been able to achieve this with a few of their applications. That said, the external display will be limited to the screen resolution supported by the device, so things might not look crisp on your 108" LCD :-)
Platforms:
This should work on all iPads and on iPhones running 4.0+. You'll need the special cable which I believe is unique for iPhone and iPad ($30-40).

iPhone: Custom UIImagePickerController?

It seems like the built in UIImagePickerController cannot accept sources other than its device camera Roll.
I would like to get the functionality of picking and enlarging pictures within my own app. Also I would like to allow the user to select the pictures and save it into their camera roll (so they can later use it as wall paper)
1) what is the recommended way of building a custom UIImagePickerController that supports what I need ? Is there another built in controller I am missing?
3) Is there a way to take a UIImage and save it to the desktop background of the device directly? Or is it a two step (first save to camera roll), then have the user load the picture from there to save as wallpaper
Thanks in advance!!
At this point, it seems that the only way to build a custom UIImagePickerController functionality is to subclass, and then muck with the view hierarchy directly. This allows you to move, hide, and replace UI elements and access the non-public classes that control the operation of the camera, but as you probably gather, this technique is both unsupported (in that it may, and probably will, break with future updates) and not recommended (in that it may, and probably will, get your app rejected from the App Store if detected).
As far as your second point (somehow numbered 3), John is right: there is no call in the public SDK to accomplish this. You could probably hack something together if you're clever, but remember the warnings in my first paragraph...
Regarding #3) there is no public call in the SDK to save an UIImage to the desktop.
I don't know about the rest of your questions though.
Just today I started a open source UIImagePickerController clone, it is not perfect but it works quite ok. Feel free to fork http://github.com/jeena/JPImagePickerController

Programmatically change iPhone Background

is it possible to change the iPhone background from code?
If you write a new png to /User/Library/LockBackground.png and then call notify_post(" com.apple.language.changed"); the device will respring and your new background will be present.
This isn't technically a private API, but does fall outside of what Apple allows on the store.
Nope, you can only save a picture for the user to set as a background.
Mel is correct, there's no way to skip over the save process.
The reason this will always be the case:
Apple doesn't want apps to be able to set the background immediately upon opening. Theoretically, they could have a permission box (like the location dialog), but I doubt that will happen anytime soon.