AIR for iOSでスクリーンショットをカメラロールに保存するANEを作ってみたけど真っ白な画面しか取れない

More than 5 years have passed since last update.

//

// ScreenShotANE.m
// ScreenShotANE
//
// Created by sakurai hiroyuki on 12/07/14.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "ScreenShotANE.h"
#import <QuartzCore/QuartzCore.h>
#import <UIKit/UIKit.h>

#define DEFINE_ANE_FUNCTION(fn) FREObject (fn)(FREContext context, void* functionData, uint32_t argc, FREObject argv[])

#define MAP_FUNCTION(fn, data) { (const uint8_t*)(#fn), (data), &(fn) }

//APIとなるメソッド
//FREObject TweetPost(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) {
DEFINE_ANE_FUNCTION(SaveScreenShot)
{
id delegate = [[UIApplication sharedApplication] delegate];
UIWindow* stage = [delegate window];

UIGraphicsBeginImageContextWithOptions(stage.frame.size, NO, 0);

//UIView.layerが真っ白。Flashの表示領域はどうしていしたらいいの???
[stage.layer renderInContext:UIGraphicsGetCurrentContext()];

NSData *pngData = UIImagePNGRepresentation(UIGraphicsGetImageFromCurrentImageContext());
UIImage *screenImage = [[UIImage imageWithData:pngData] retain];

UIImageWriteToSavedPhotosAlbum(screenImage, nil, nil, nil);
UIGraphicsEndImageContext();

NSLog(@"++++++save++++++");

return NULL;

}

//初期化関数
void SaveScreenShotContextInitializer(void* extData, const uint8_t* ctxType, FREContext ctx,
uint32_t* numFunctionsToTest, const FRENamedFunction** functionsToSet) {
*numFunctionsToTest = 1;
FRENamedFunction* func = (FRENamedFunction*)malloc(sizeof(FRENamedFunction)*1);
func[0].name = (const uint8_t*)"SaveScreenShot"; //ネイティブ拡張関数名
func[0].functionData = NULL;
func[0].function = &SaveScreenShot; //ネイティブコード関数のポインタ

*functionsToSet = func;
}
void SaveScreenShotContextFinalizer(FREContext ctx) {
return;
}
void SaveScreenShotExtInitializer(void** extDataToSet, FREContextInitializer* ctxInitializerToSet,
FREContextFinalizer* ctxFinalizerToSet) {
*extDataToSet = NULL;
*ctxInitializerToSet = &SaveScreenShotContextInitializer;
*ctxFinalizerToSet = &SaveScreenShotContextFinalizer;
}
void SaveScreenShotExtFinalizer(void* extData) {
return;
}