Detect when the user takes a screenshot

Forums Programming cocos2d support (graphics engine) Detect when the user takes a screenshot

This topic contains 9 replies, has 7 voices, and was last updated by  varedis 2 years ago.

Viewing 10 posts - 1 through 10 (of 10 total)
Author Posts
Author Posts
March 29, 2012 at 11:11 am #240278

Yohan85
Participant
@yohan85

Hi all,

I’d like to have a callback when the user has taken a screenshot from my game. After reading posts on the web, it seems that it is not possible with iOs 5. (as mentioned here)

So basically I thought I could check every second if an image has been aded to the photo album, then calculate something like its average tone (+ highest color, + lowest color), and then compare it to the screen view of my game.

DO you think it is the best way to do ? Will Apple block my game if they find out I use this ?

March 29, 2012 at 11:25 am #370440

bummzack
Participant
@bummzack

Why would you want to do that?

March 29, 2012 at 11:52 am #370441

andershaf
Participant
@andershaf

Yohan85, if you really want to detect when a user takes a screenshot, I think that is the only way. The only problem is that you have to require location services since the photos may contain gps data.

March 29, 2012 at 12:22 pm #370442

Yohan85
Participant
@yohan85

Bummzack > Well I’m making a riddle game, and one of my levels will require the user to take a photo to go to the next one. Nothing bad, don’t worry… And the callback will happen AFTER the ssnapshot, so I’m not preventing anyone to do a snap.

andershaf > what do you mean by “require” location services ? I don’t need GPS data, I think I’ll just use the colored pixels to compare the two images…

March 29, 2012 at 2:57 pm #370443

clarus
Moderator
@clarus

Instead of making them take a screenshot, why don’t you just create an image from your view contents with a button in the app and add that to the camera roll? There’s code for doing that somewhere. Polling the albums every second is hacky.

March 29, 2012 at 3:29 pm #370444

Yohan85
Participant
@yohan85

Well the whole thing is to make the user “guess” that he needs to take a screenshot of the app (that’s the riddle) so I can’t really push it away…

What do you mean by “hacky” ? Hacky like “apple doesnt like it” or like “not a really clear way of coding” ?

March 29, 2012 at 3:42 pm #370445

clarus
Moderator
@clarus

Both definitions I guess. I mean, polling the camera albums every second just doesn’t sound like a good solution for anything. When a screenshot is taken, is there an applicationWillResignActive/applicationDidBecomeActive cycle? If so, only check the albums when the app becomes active again since the screenshot couldn’t have occurred any other time. The problem I see is what if they’re running your app at this stage and sync their 5,000 new honeymoon photos or go in the background and take two dozen pictures of cows? You’re going to load and check every image when you come back? That’s going to be really slow.

If you absolutely have to do this kind of an image check, I’d probably just check for some key small elements in 2 or 3 positions in the image rather than running through every pixel. You should be able to come up with a quick check like that which is extremely unlikely to match anything except your screen. The loading time for the image is going to be slow, though.

March 29, 2012 at 4:36 pm #370446

MichaelB
Participant
@michaelb

Some of our non-game apps can display the camera roll contents using the ALAssetsLibrary stuff. Several huge problems, I think you’ll need a different puzzle for that page.

As andershaf said, the first time your app tries to access the assets library, a prompt about granting access to location data appears. That’s because photos can contain GPS information. iOS will ask automatically.

And the second is it’s way to slow to poll. On my iPhone 4S, with about 1500 photos, it takes 15 seconds to load. Not something you’re going to be able to poll at all.

Finally, while all us developers know how to take a screenshot of the device, I’m sure its a very small percent of average users who know how to do that.

March 30, 2012 at 1:07 am #370447

HiRez
Participant
@hirez

If you’re using Kobold2D (extensions to Cocos2D), you can just use the KKScreenshot class to make your own snapshot. You can either keep this in memory (without cluttering up your photo library), or you can save it to a file. This way you know when the shot was taken because you initiated it yourself in the app code, and you know where to find the image as well.

If you don’t want to install Kobold2D (which I recommend you do), here is the source code for that:

https://github.com/kobold2d/Kobold2D/blob/b76baa245dac8b7f4eecf3e9d8afab90a31fb1d2/Kobold2D/__Kobold2D__/kobold2d/KKScreenshot.m

March 30, 2012 at 8:03 am #370448

varedis
Moderator
@varedis

@HiRez – That wouldn’t work with the initial post though, he wants the user to take a screenshot using them home and power button so it would take a standard iOS screenshot. With your solution he would have to provide a button for them to click on to take a photo which kind of defeats the whole purpose of the riddle.

I agree with the others, this type of riddle is not practical, plus with possible new guidelines coming in where the user has to specifically allow the app to access their photos then the user could decline and would be forever stuck on the puzzle.

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.