我刚刚更新到XCode 4.2,我看到一个很酷的功能,允许我手动设置设备位置.有没有人知道以编程方式完成同样的事情的方法?我想在一些单元测试中设置位置.
我正在用我的应用程序拍照,调用委托方法,图像保存在库中,但是我在日志中出现了崩溃错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSInvocation invocationWithMethodSignature:]: method signature argument cannot be nil'
*** Call stack at first throw:
(
0 CoreFoundation 0x33ac0987 __exceptionPreprocess + 114
1 libobjc.A.dylib 0x3347b49d objc_exception_throw + 24
2 CoreFoundation 0x33a6b05d +[NSInvocation invocationWithMethodSignature:] + 340
3 PhotoLibrary 0x3038da11 __-[PLAssetsSaver _createWriteImageCompletionBlockWithImage:target:selector:contextInfo:]_block_invoke_1 + 96
4 PhotoLibrary 0x3038d7cd __-[PLAssetsSaver _saveImage:imageData:properties:completionBlock:]_block_invoke_2 + 56
5 PhotoLibrary 0x3038de87 __-[PLAssetsSaver queueJobData:requestEnqueuedBlock:completionBlock:imagePort:previewImagePort:]_block_invoke_2 + 122
6 libSystem.B.dylib 0x33c32680 _dispatch_call_block_and_release + 20
7 libSystem.B.dylib 0x33c32e38 _dispatch_main_queue_callback_4CF + 220
8 CoreFoundation 0x33a482ab …Run Code Online (Sandbox Code Playgroud) 当我使用CGContext绘制一些文本时,它被镜像绘制.
我尝试应用一些变换,然后绘制得很好,但是其余的绘图和所有坐标似乎都画得很糟糕.
我尝试保存和恢复上下文,然后绘制文本(和aplying转换),但这没有帮助.
如何使用CGContext将一些文本绘制到视图上而不影响绘图的其余部分,以及该文本的屏幕CGPoint坐标?
我根据不同的来源编写了以下UIDevice类别.我已经升级了这个platformCode方法,所以它的水平低于可以看到的水平.
这很好用,但platformCode方法很低.你知道这种电话是否可以用Cocoa Touch代码取代吗?这是相关的代码:
UIDevice_enhanced.h
@interface UIDevice (Enhanced)
typedef enum {
kUnknownPlatform = 0,
kiPhone1G,
kiPhone3G,
kiPhone3GS,
kiPhone4,
kiPhone4Verizon,
kiPhone4S,
kiPodTouch1G,
kiPodTouch2G,
kiPodTouch3G,
kiPodTouch4G,
kiPad,
kiPad2Wifi,
kiPad2GSM,
kiPad2CMDA,
kSimulator
} PlatformType;
- (NSString *) platformName;
- (PlatformType) platform;
@end
Run Code Online (Sandbox Code Playgroud)
UIDevice_enhanced.m
#import "UIDevice_enhanced.h"
#include <sys/utsname.h>
@interface UIDevice (Enhanced)
- (NSString *) platformCode;
@end
@implementation UIDevice (Enhanced)
// Utility method (private)
- (NSString*) platformCode {
struct utsname systemInfo;
uname(&systemInfo);
NSString* platform = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
return platform;
}
// …Run Code Online (Sandbox Code Playgroud) 我在objective-c中读过很多关于枚举类型的东西,我看到有很多方法可以定义它们.但是我没有看到正确的方法(如果有的话)来定义可以使用CARS.ROLLSROYCE调用的枚举,并且不能仅在代码中使用ROLLSROYCE.
所以我可以在CARS枚举中以及BEAUTIFULCARS枚举中定义ROLLSROYCE.
你知道定义这样一个枚举的方法吗?
在我的应用程序中,我希望用户能够拍照或使用照片库中的照片.当用户点击按钮时,我弹出警报视图,用户可以选择拍摄新照片或照片库中的照片.这是我用过的代码:
- (void)PictureAlert:(id)sender {
UIAlertView *AlertDialog;
// Setting up AlertDialog.
AlertDialog = [[UIAlertView alloc] initWithTitle:nil
message:nil
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Choose From Library", @"Take New Picture", nil];
[AlertDialog show]; }
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *ButtonTitle = [alertView buttonTitleAtIndex:buttonIndex];
if ([ButtonTitle isEqualToString:@"Choose From Library"]) {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
// Pick photo.
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:picker animated:YES];
} else if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
// Setting up AlertDialog.
UIAlertView …Run Code Online (Sandbox Code Playgroud) 我在某些应用程序中使用了一些方法,这些方法现在被标记为自iOS5以来已弃用.我想知道这些更新何时变得紧急.
那么,通常,弃用的方法何时变得过时?iOS 5.1有可能出现这种情况吗?或者这总是与iOS 6.0这样的主要版本?
我有这个代码:
- (void)viewDidLoad
{
[super viewDidLoad];
CLLocationCoordinate2D userLocation = CLLocationCoordinate2DMake(48.9793946200, 2.4726272850);
CLLocationDistance dist1 = 636.9887048804;
CLLocationDistance dist2 = 900.8380655203;
CLLocationDistance dist = dist1;
[self.myMapView setRegion:MKCoordinateRegionMakeWithDistance(userLocation, dist, dist) animated:YES];
// TEST
// ------------------------------------------------------------
MKCoordinateRegion region = self.myMapView.region;
CLLocationDegrees lat = region.center.latitude;
CLLocationDegrees lon = region.center.longitude - region.span.longitudeDelta/2;
CLLocation *west = [[[CLLocation alloc] initWithLatitude:lat longitude:lon] autorelease];
NSLog(@"User location: lat : %.10lf long : %.10lf", userLocation.latitude, userLocation.longitude);
NSLog(@"distance set: %.10lfm", dist);
NSLog(@"center: lat : %.8lf long : %.8lf", region.center.latitude, region.center.longitude);
CLLocation* centerRegion = …Run Code Online (Sandbox Code Playgroud) 新的iCloud服务有许多可能的配置.我如何知道我的用户设备是否配置为将拍摄的照片发送到iCloud服务器而不是仅将其存储在设备上?
我使用这种方法来获取磁盘上的可用空间,从一些研究后发现的代码中提取.
float freeSpace = -1.0f;
NSError* error = nil;
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSDictionary* dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
if (dictionary) {
NSNumber* fileSystemSizeInBytes = [dictionary objectForKey:NSFileSystemFreeSize];
freeSpace = [fileSystemSizeInBytes floatValue];
}
Run Code Online (Sandbox Code Playgroud)
我想知道为什么在运行这个时,它给了我3660062720.000000字节的可用空间,这将给出3,408699035644531 Gb(/ 1024/1024/1024)
但是看看我的iPhone设置 - >一般信息(还有iTunes),我说我的iPhone只剩下3.2 Gb了.
哪里出错了?
iphone ×8
cocoa-touch ×3
ios ×3
objective-c ×3
camera ×2
callback ×1
definition ×1
deprecated ×1
diskspace ×1
enums ×1
exception ×1
filesystems ×1
google-maps ×1
icloud ×1
image ×1
interface ×1
ios5 ×1
ipad ×1
ipod ×1
itunes ×1
mkmapview ×1
obsolete ×1
save ×1
sdk ×1
settings ×1
text ×1
xcode ×1
xcode4.2 ×1