Creating an image out of the ios surface and saving it
I remember I saw something on this subject (taking screenshots in the background) some time ago. I wasn't able find exact place and code which I saw. The only note which I left for myself was usage of createScreenIOSurface
I googled a little bit and found couple of mentions:
Get a screenshot while App is in background? (Private APIs allowed)
https://github.com/rpetrich/FastBlurredNotificationCenter/blob/master/Tweak.x
http://pastie.org/pastes/3734430
As I remember the code was way more compact then what you showed.
is AVAssetImageGenerator completion handler called in main thread?
IIRC, yes. But you can test it, and to be safe you can wrap your code in a block which dispatches it to the main thread.
Generally speaking, the callback has to return to the main thread as the thread it's started from can't be guaranteed to be running a run loop if it isn't the main thread.
Unless you're scheduling the block you're creating in relation to other operations (dependencies) then I'm not sure what advantage the block gives you as the image loading is asynchronous so you can trigger it from the main thread without blocking anything.
From your comment, in that case you should switch your code around. Create the block operation inside the completion block which provides you with the image. Add each block operation to your queue. The block operation just takes the image and saves it to disk.
Storing images in Core Data or as file?
There are two main options:
- Store the file on disk, and then store the path to the image in core data
- Store the binary data of the image in core data
I personally prefer the 1st option, since it allows me to choose when I want to load the actual image in memory. It also means that I don't have to remember what format the raw data is in; I can just use the path to alloc
/init
a new UIImage
object.
Related Topics
Why Is an Nsdate in a Core Data Managed Object Converted to Nstimeinterval
Property 'Self.*' Not Initialized at Super.Init Call
How to Access User Defined Runtime Attribute from the 'Sender' Object
Confirm Back Button on Uinavigationcontroller
How to Access the Accelerometer from the Apple Watch
Changing Uipageviewcontroller's Page Programmatically Doesn't Update the Uipagecontrol
How to Encrypt and Decrypt a String(Plain Text) with Rsa Public Key in iOS, Swift
Mkmapview Doesn't Zoom Correctly While User Tracking Mode Is Mkusertrackingmodefollowwithheading
Insert String at Cursor Position of Uitextfield
Code Signing Issue in Xcode Version 8
Physicsbody Doesn't Adhere to Node's Anchor Point
Declaring Global Variables in Swift
Multiple Localized .Strings Files in iOS App Bundle
How to Encrypt Using Aes Gcm on iOS