我是JSON-C的新手,请查看我的示例代码,让我知道它会创建任何内存泄漏,如果是,那么如何释放JSON-C对象.
struct json_object *new_obj = NULL;
new_obj = json_tokener_parse(strRawJSON);
new_obj = json_object_object_get(new_obj, "FUU");
if(NULL == new_obj){
SYS_OUT("\nFUU not found in JSON");
return NO;
}
new_obj = json_object_object_get(new_obj, "FOO"); // I m re-using new_obj, without free it?
if(NULL == new_obj){
SYS_OUT("\nFOO not found in JSON");
return NO;
}
// DO I need to clean new_obj, if yes then how ??
Run Code Online (Sandbox Code Playgroud)
我是否需要清理new_obj,如果是,那么如何.有人可以帮助理解如何进行内存管理JSON-C.
提前致谢
如何在iOS中使用公钥验证数字签名而不使用任何第三方代码(例如)打开SSL?
我需要使用公钥验证iOS App中的数字签名.有人可以帮助我在不使用第三方软件的情况下实现这一目标.
我正在尝试下面的代码,但问题是我的应用程序中没有证书,因此无法创建SecTrustRef.
码:
NSString *certPath = [[NSBundle mainBundle] pathForResource:@"yyy"
ofType:@"xxx"];
SecCertificateRef myCertificate = nil;
NSData *certificateData = [[NSData alloc] initWithContentsOfFile :certPath];
myCertificate = SecCertificateCreateWithData(kCFAllocatorDefault, (__bridge CFDataRef)certificateData);
SecPolicyRef myPolicy = SecPolicyCreateBasicX509();
SecTrustRef trustRef;
SecTrustCreateWithCertificates(myCertificate, myPolicy, &trustRef);
SecKeyRef keyRef = SecTrustCopyPublicKey (trustRef);
BOOL status = SecKeyRawVerify (keyRef,
kSecPaddingPKCS1SHA1,
(const uint8_t *)[data bytes],
(size_t)[data length],
(const uint8_t *)[signature bytes],
(size_t)[signature length]
);
Run Code Online (Sandbox Code Playgroud)
我有以下内容:
如果我不想使用ant第三方开源,请帮助我在iOS SDK中拥有的所有选项.
我想知道提供一个通过wifi与第三方硬件交互的iOS应用程序的所有可能性.
问候,
我试图使用下面的代码将我的UIView转换为UIImage.
+ (UIImage *) imageWithView:(UIView *)view{
float scale = 1.0f;
UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, scale);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage* img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
view.layer.contents = nil;
return img;
}
Run Code Online (Sandbox Code Playgroud)
这段代码有两个问题.
1.当我在后台线程中运行此代码时(!mainThread)
在后台线程中调用renderInContext时,我遇到了内存泄漏问题.
2.当我在主线程上运行此代码时
没有内存泄漏但是在iPad 3上我在从UIView创建图像时遇到了一些性能问题(当调用此方法时我的UI挂起).因为我需要在几秒钟内调用此函数超过5次,因此UI挂起会给用户带来非常糟糕的体验.
如果我在这里做错了什么,请指导我?