Question

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

Was it helpful?

Solution

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
    ...
}

OTHER TIPS

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).

In order to avoid asking for GPS permissions just to know whether or not the GPS exists, I use a little trick. Since all the devices with a real GPS also have 3G I just check if the device has a phone operator.

//Use classLoaders to avoid crashes on iPhone OS 3.x
id netInfo = [[NSClassFromString(@"CTTelephonyNetworkInfo") alloc] init];
if (netInfo) 
{
            id carrier = [netInfo subscriberCellularProvider];

            if ([[carrier carrierName] length] <=0)
            {
                    //NO operator=>NO 3G and no real GPS  
            }
}
[netInfo release];

Of course this may not be 100% future proof but it works well at this point. I use it in my Battery HD app in order to hide GPS estimates so I obviously don't want to ask the user for authorizations for that.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top