在iPhone中检测GPS硬件 [英] Detect GPS Hardware in iphone

查看:1347
本文介绍了在iPhone中检测GPS硬件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何检测iPhone中的GPS硬件,或者不知道如何解决这个问题。

即使你不能确定这一点使用SDK,您可能会利用您对当前模型的了解。如果您仅限于iPhone 3G,iPhone 3GS和iPod Touch第二代(我不亲自支持较旧的iPhone边缘或iPod Touch第一代),那么您已经知道iPhone机型配备了真正的AGPS装置,而iPod Touch 2nd世代可以使用 - 如果可用 - 地理标记的无线热点。您可以使用以下方法确定您正在运行的模型:

   - (NSString *)deviceModel {
size_t size;
sysctlbyname(hw.machine,NULL,& size,NULL,0);
char * answer = malloc(size);
sysctlbyname(hw.machine,answer,&size,NULL,0);
NSString * results = [NSString stringWithCString:answer encoding:NSUTF8StringEncoding];
free(answer);
返回结果;
}

该方法为3GS返回@iPhone2,1,@iPhone1 ,2为3G和@iPod2,1为iPod touch第二代;你调用它如下

  NSString * deviceModel = [[self deviceModel] retain]; 

并如下使用它:

<$ p $ [code> if([self.deviceModel isEqualToString:@Pod2,1]){
//没有真正的GPS单元可用
//没有相机可用
...
}


I want to know how to detect GPS HardWare in present in Iphone or not

解决方案

Even though you can not determine this using the SDK, you may exploit your knowledge of current models. If you limit yourself to iPhone 3G, iPhone 3GS and iPod Touch 2nd generation (I do not personally support older iPhone edge or iPod Touch 1st generation), then you already know that the iPhone models ship with a real AGPS unit while the iPod Touch 2nd generation can use - if and when available - geotagged wifi hot spots. You may then use the following method to determine the model you are running on:

- (NSString *) deviceModel{
    size_t size;
    sysctlbyname("hw.machine", NULL, &size, NULL, 0);
    char *answer = malloc(size);
    sysctlbyname("hw.machine", answer, &size, NULL, 0);
    NSString *results = [NSString stringWithCString:answer encoding: NSUTF8StringEncoding];
    free(answer);
    return results;
}

The method returns @"iPhone2,1" for the 3GS, @"iPhone1,2" for the 3G and @"iPod2,1" for the ipod touch 2nd generation; you call it as follows

NSString *deviceModel = [[self deviceModel] retain];

and use it as follows:

if([self.deviceModel isEqualToString:@"Pod2,1"]){
    // no real GPS unit available 
    // no camera available
    ...
}

这篇关于在iPhone中检测GPS硬件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆