我正在开发一个使用JavascriptCore具有脚本功能的iOS 7应用程序.
我想有办法暂停或完全停止当前在JSContext上运行的代码.JavascriptCore没有很好的文档,所以我找不到答案.
我有一些想法:
但希望有更好的方法.
任何帮助,将不胜感激.谢谢!
我正在尝试从UIImage对象创建渐进式jpeg ,这是我的代码
NSMutableData *data = [NSMutableData data];
NSString *path = [NSHomeDirectory() stringByAppendingPathComponent: @"Library/Caches/test.jpg"];
CFURLRef url = CFURLCreateWithString(NULL, (CFStringRef)[NSString stringWithFormat:@"file://%@", path], NULL);
CGImageDestinationRef destination = CGImageDestinationCreateWithURL(url, kUTTypeJPEG, 1, NULL);
CFRelease(url);
NSDictionary *jfifProperties = [NSDictionary dictionaryWithObjectsAndKeys:
(__bridge id)kCFBooleanTrue, kCGImagePropertyJFIFIsProgressive,
nil];
NSDictionary *properties = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat:.7], kCGImageDestinationLossyCompressionQuality,
jfifProperties, kCGImagePropertyJFIFDictionary,
nil];
CGImageDestinationAddImage(destination, ((UIImage*)object).CGImage, (__bridge CFDictionaryRef)properties);
CGImageDestinationFinalize(destination);
CFRelease(destination);
Run Code Online (Sandbox Code Playgroud)
这在模拟器中运行时效果很好,但不幸的是在设备上产生了粗糙/块状结果:

关于发生了什么的任何想法?我将恢复使用UIImageJPEGRepresentation作为最后的手段,我真的需要渐进式JPEG.
我一直在玩新的iOS 7/Mavericks JavascriptCore桥,尝试将Objective-C上的JS函数作为块.
JavascriptCore头文件声明只要支持每个参数,这是可能的,但尝试这样做:
JSContext *context = [[JSContext alloc] init];
context[@"Log"] = ^(NSString *message){NSLog(@"%@", message);};
context[@"BlockTest"] = ^(void (^blockTest)(NSString* blockString)){
NSLog(@"Calling Block Test");
blockTest(@"STRINGGGGG");
};
[context evaluateScript:@"BlockTest( function(dataString){Log('JS '+dataString);} )"];
Run Code Online (Sandbox Code Playgroud)
引发以下JS异常:
TypeError: '[object NSBlock]' is not a function (evaluating 'BlockTest( function(dataString){Log('JS '+dataString);} )')
Run Code Online (Sandbox Code Playgroud)
关于我的测试代码有什么问题的任何想法?
javascript webkit objective-c objective-c-blocks javascriptcore