iOS Question [SOLVED] iOS fake location

Inrenbang

Member
Licensed User
Hello is there a way to detect fake/mock location in iOS, based on this thread : https://stackoverflow.com/a/75973050
C-like:
let locationManager = CLLocationManager()
        if #available(iOS 15.0, *) {
            // use UICollectionViewCompositionalLayout
            let isLocationSimulated = locationManager.location?.sourceInformation?.isSimulatedBySoftware ?? false
            let isProducedByAccess = locationManager.location?.sourceInformation?.isProducedByAccessory ?? false
            
            let info = CLLocationSourceInformation(softwareSimulationState: isLocationSimulated, andExternalAccessoryState: isProducedByAccess)
            
            if info.isSimulatedBySoftware == true || info.isProducedByAccessory == true{
                result(true)
            } else {
                result(false)
            }
        }
        else{
            result(false)
        }

requirement is iOS 15, how can we use it on our b4i?
 

Inrenbang

Member
Licensed User
i dont know if this working on real device, i tested it using emulator (iphone 16, ios 18) but always false

B4X:
Public Sub isFakeLocation As Boolean
    Dim osv As Float = App.OSVersion
    If osv < 15 Then
        Return False
    End If
    Dim no As NativeObject = Me
    Return no.RunMethod("cekspoof",Null).AsBoolean
End Sub

#if objc
#import <CoreLocation/CoreLocation.h>
- (BOOL)cekspoof {
    bool hasil;
    CLLocationSourceInformation *srcInfo;
    hasil = srcInfo.isSimulatedBySoftware;
    if (hasil) {
        return hasil;
    }
    hasil = srcInfo.isProducedByAccessory;
    return hasil;
}
#End If

can someone test it?
 
Upvote 0

Inrenbang

Member
Licensed User
Solved now :

B4X:
Public Sub isFakeLocation As Boolean
    Dim osv As Float = App.OSVersion
    If osv < 15 Then
        Return False
    End If
    Dim no As NativeObject = Me
    Return no.RunMethod("cekspoof",Null).AsBoolean
End Sub

#if objc
#import <CoreLocation/CoreLocation.h>
- (BOOL)cekspoof {
        
    CLLocationManager *locMngr;
    
    locMngr = [[CLLocationManager alloc] init];
    
    return locMngr.location.sourceInformation.isSimulatedBySoftware || locMngr.location.sourceInformation.isProducedByAccessory ? true : false;

}
#End If

requirement is iOS 15, that mean iPhone 6 & iPhone 6s cannot detect, don't forget you have to enable gps and location.
 
Upvote 0
Top