我正在开始一个使用coreLocation和mapkit框架的新应用程序.
我的问题是试图让当前的速度总是给我一个负值,我把我的iPhone带到一个有3g信号的地方并没关系,location.speed值总是-1.
这是重要的代码:
#define kRequiredAccuracy 1500.0 //meters
#define kMaxAge 60.0 //seconds
Run Code Online (Sandbox Code Playgroud)
在init方法中:
self.locationManager=[[CLLocationManager alloc] init];
self.locationManager.delegate=self;
self.locationManager.desiredAccuracy=kCLLocationAccuracyNearestTenMeters;
Run Code Online (Sandbox Code Playgroud)
然后didUpdateToLocation:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
NSTimeInterval ageInSeconds = [newLocation.timestamp timeIntervalSinceNow];
NSLog(@"Location: %@", [newLocation description]);
if( newLocation.horizontalAccuracy > kRequiredAccuracy || fabs(ageInSeconds) > kMaxAge )
{
NSLog(@"inacurate position");
[self.delegate inacuratePosition];
}
else {
[self.delegate locationUpdate:newLocation andOldLocation:oldLocation];
location=newLocation.coordinate;
}
if(tracking)
{
[self updatePosition];
}
if(firstTime)
{
[self placeStartMark];
firstTime=FALSE;
}
}
Run Code Online (Sandbox Code Playgroud)
最后在我正在实现协议的视图控制器中:
- (void)locationUpdate:(CLLocation *)newLocation andOldLocation:(CLLocation*)oldLocation{
double speed = [newLocation speed] *3.6;
double …Run Code Online (Sandbox Code Playgroud) 我试图用这种方法加密目标c中扩展NSData的字符串:
@implementation NSData (AES128)
(NSData *)AES128Encrypt {
char keyPtr[kCCKeySizeAES128] = {'\xe1','\xaa','\x9c','\x61','\x46','\x74','\x44','\x56','\xf0','\xe5','\x47','\x46','\x86','\xdc','\x95','\x77'};
NSUInteger dataLength = [self length];
size_t bufferSize = dataLength + kCCBlockSizeAES128;
void *buffer = malloc(bufferSize);
size_t numBytesEncrypted = 0;
CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt,kCCAlgorithmAES128,kCCOptionPKCS7Padding,keyPtr,kCCKeySizeAES128,NULL /* initialization vector (optional) /,[self bytes], dataLength, / input /buffer, bufferSize, / output */
&numBytesEncrypted);
if (cryptStatus == kCCSuccess) {
//the returned NSData takes ownership of the buffer and will free it on deallocation
return [NSData dataWithBytesNoCopy:buffer length:numBytesEncrypted];
}
free(buffer); //free the buffer;
return nil;
} …
Run Code Online (Sandbox Code Playgroud) 我试图隐藏导航控制器顶部栏从我的故事板视图,因为我实际上是以编程方式隐藏它,当Iloit在执行时间被重新标记
这是一张图片,您可以更好地理解它:

顶部栏它没有出现在我的应用程序中,我也想将它隐藏在故事板中.任何线索?
提前致谢!