Search code examples
iosiphonegpscore-locationdetection

Detect GPS Hardware in iphone


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


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