Voglio catturare uno screenshot da un servizio in background. L'API privata va bene, in quanto non è necessario inviarla all'app store. Ho già provato UIGetScreenImage e non funziona dall'app in background.IOSurface - IOS Private API - Cattura screenshot in background
Sto usando il seguente codice che ho ricevuto da SO. IOSurfaceCreate restituisce null a me. Qualsiasi aiuto apprezzato.
CFMutableDictionaryRef dict;
IOSurfaceRef screenSurface = NULL;
char pixelFormat[4] = {'A','R','G','B'};
dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
uint32_t width ;
uint32_t height;
void *pitch;
void *bPE;
void *size;
CFDictionarySetValue(dict, kIOSurfaceIsGlobal, kCFBooleanTrue);
CFDictionarySetValue(dict, kIOSurfaceBytesPerRow, CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &pitch));
CFDictionarySetValue(dict, kIOSurfaceBytesPerElement, CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &bPE));
CFDictionarySetValue(dict, kIOSurfaceWidth, CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &width));
CFDictionarySetValue(dict, kIOSurfaceHeight, CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &height));
CFDictionarySetValue(dict, kIOSurfacePixelFormat, CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, pixelFormat));
CFDictionarySetValue(dict, kIOSurfaceAllocSize, CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &size));
IOSurfaceRef destSurf = IOSurfaceCreate(dict);
IOSurfaceAcceleratorRef outAcc;
IOSurfaceAcceleratorCreate(NULL, 0, &outAcc);
CFDictionaryRef ed = (__bridge CFDictionaryRef)[NSDictionary dictionaryWithObjectsAndKeys: nil];
IOSurfaceAcceleratorTransferSurface(outAcc, screenSurface, destSurf, ed, NULL);
uint32_t aseed;
IOSurfaceUnlock(screenSurface, kIOSurfaceLockReadOnly, &aseed);
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, IOSurfaceGetBaseAddress(destSurf), (width*height*4), NULL);
CGImageRef cgImage=CGImageCreate(width, height, 8, 8*4, IOSurfaceGetBytesPerRow(destSurf), CGColorSpaceCreateDeviceRGB(), kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little, provider, NULL, YES, kCGRenderingIntentDefault);
UIImage *image = [UIImage imageWithCGImage: cgImage];
UIImageWriteToSavedPhotosAlbum(image, self_object, nil, nil);
CGImageRelease(cgImage);
CFRelease(destSurf);
Hai funzionato su iOS 7? Ricevo un errore di Linker su IOMobileFramebufferOpen. Potresti per favore condividere quali framework/lib esattamente per collegare e dove hai preso le intestazioni? – Frank
con l'aggiunta di questo cmd del terminale per eliminare gli errori provenienti da iOSurface > cd/Applicazioni/Xcode.app/Contenuto/Sviluppatore/Piattaforme/iPhoneOS.platform/Sviluppatore/SDK/iPhoneOS7.0.sdk/Sistema/Libreria/Framework/IOKit. framework > sudo ln -s Versioni/A/IOKit – HDNZ
Qualcuno ha un progetto dimostrativo funzionante per iOS 8? O puoi dirmi come usare questa struttura/ottenere una presa delle intestazioni? – Max