我需要在iOS应用程序中创建一个假va_list的传递给NSString initWithFormat:arguments:函数,这是我的代码:
NSArray *fixedArguments = [[NSArray alloc] initWithArray:arguments];
NSRange range = NSMakeRange(0, [fixedArguments count]);
va_list fakeArgList = (va_list)malloc(sizeof(NSString *) * [fixedArguments count]);
__unsafe_unretained id *ptr = (__unsafe_unretained id *)fakeArgList;
[fixedArguments getObjects:ptr range:range];
content = [[NSString alloc] initWithFormat:outputFormat
arguments:(va_list)fakeArgList];
free(fakeArgList);
Run Code Online (Sandbox Code Playgroud)
编译器在转换线上抱怨此消息:
error: cast of a non-Objective-C pointer type 'va_list' (aka 'char *') to '__unsafe_unretained id *' is disallowed with ARC
Run Code Online (Sandbox Code Playgroud)
该getObjects:range:功能定义如下:
- (void)getObjects:(id __unsafe_unretained [])objects range:(NSRange)range;
Run Code Online (Sandbox Code Playgroud)
我已经尝试了一切,但仍然无法摆脱这个错误......
是否有va_list启用ARC 创建假的解决方案?我究竟做错了什么?
我的主要问题是我需要获取ALAsset对象的缩略图.
我尝试了很多解决方案并搜索了堆栈溢出数天,由于这些限制,我找到的所有解决方案都不适合我:
这是我带来的代码的最后一次迭代:
#import <AssetsLibrary/ALAsset.h>
#import <ImageIO/ImageIO.h>
// ...
ALAsset *asset;
// ...
ALAssetRepresentation *assetRepresentation = [asset defaultRepresentation];
NSDictionary *thumbnailOptions = [NSDictionary dictionaryWithObjectsAndKeys:
(id)kCFBooleanTrue, kCGImageSourceCreateThumbnailWithTransform,
(id)kCFBooleanTrue, kCGImageSourceCreateThumbnailFromImageAlways,
(id)[NSNumber numberWithFloat:200], kCGImageSourceThumbnailMaxPixelSize,
nil];
CGImageRef generatedThumbnail = [assetRepresentation CGImageWithOptions:thumbnailOptions];
UIImage *thumbnailImage = [UIImage imageWithCGImage:generatedThumbnail];
Run Code Online (Sandbox Code Playgroud)
问题是,结果CGImageRef既不是由方向变换的,也不是由指定的最大像素大小变换的;
我也试图找到一种调整大小的方法CGImageSource,但是:
CGImageSourceCreateWithURL:;ALAsset或ALAssetRepresentation一个CGDataProviderRef与使用CGImageSourceCreateWithDataProvider:;CGImageSourceCreateWithData: 要求我将fullResolution或全屏资产存储在内存中才能工作.我错过了什么吗?
有没有从获得自定义缩略图的另一种方式ALAsset或者ALAssetRepresentation说我失踪?
提前致谢.
我在一个UIViewController中,self.view指向一个帧为300x480的有效视图.
UIView *redView;
UIView *blueView;
//[[self view] setAutoresizingMask:YES]; //WRONG!
[[self view] setAutoresizesSubviews:YES];
[[self view] setClipsToBounds:YES];
redView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
[redView setBackgroundColor:[UIColor redColor]];
[redView setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
[[self view] addSubview:redView];
blueView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[blueView setBackgroundColor:[UIColor blueColor]];
[blueView setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin];
[[self view] addSubview:blueView];
Run Code Online (Sandbox Code Playgroud)
有了这段代码,我正在尝试
但你可以看到的结果远非我所期待的......
http://imageshack.us/photo/my-images/27/iossimulatorscreenshoto.png/
我已经阅读了关于自动调整掩码使用的每一点苹果文档和每个谷歌结果,但我仍然无法弄清楚为什么会发生这种情况.
有人可以向我解释发生了什么事吗?
提前致谢.
在应用程序未运行时,我搜索了很多处理图标标记的解决方案.
我写了一个接收推送通知的应用程序但是,在运行状态下,我可以更新application:didReceiveRemoteNotification:功能中的徽章,我仍然无法弄清楚如何在应用程序未运行时更新图标徽章.
在我的应用程序的通知菜单下,"徽章应用程序图标"开关打开,但是在接收远程通知时,图标徽章不会更新.
代码在设备上运行,不涉及模拟器.
我的通知包含徽章
$body['aps'] = array(
'alert' => $message,
'sound' => 'default',
'badge' => '1' // Wrong, see edit...
);
Run Code Online (Sandbox Code Playgroud)
我正在使用一个简单的PHP脚本来生成它.
我错过了什么吗?
编辑:
我发现我将徽章属性作为字符串而不是数字发送.
php中的正确代码是:
$body['aps'] = array(
'alert' => $message,
'sound' => 'default',
'badge' => 1 // Right
);
Run Code Online (Sandbox Code Playgroud)
使用数字徽章值,图标徽章会正确更新.
ios ×3
alasset ×1
badge ×1
cgimage ×1
ios5 ×1
ipad ×1
iphone ×1
objective-c ×1
thumbnails ×1
uiview ×1