views:

650

answers:

3

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

+2  A: 

You can't detect the hardware, at least not through the official SDK. You can, however, interact with it (namely, getting information out of it) from your application (via the CoreLocation framework). And this works in every device ever shipped since the release of iPhone OS 2.0 (even iPod touches without a real GPS inside).

Adrian Kosmaczewski
+1  A: 

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
    ...
}
unforgiven
Thanks for help
A: 

The best I found is to leverage the fact that CLLocation.verticalAccuracy is only set for GPS equipped devices. Of course this means that GPS availability can only be determined after the first location update.

From Apple's documentation:

Determining the vertical accuracy requires a device with GPS capabilities. Thus, on some earlier iOS-based devices, this property always contains a negative value.

Update: Sometimes, Core Location sends CLLocation objects with verticalAccuracy = -1 on an iPhone 4 as well. Probably it's doing that when no GPS fix is available and Core Location resorts to cell or Wi-Fi positioning. So the fact you're getting -1 doesn't necessarily mean you don't have GPS. Only if you're getting a positive value you know for sure, you do have GPS.

Ortwin Gentz