Magnetometer or Heading / Compass values on iOS 11?

Although a bit late, but just for Completeness,

I found the solution some time ago by ReImplementing the LocationServices - Plugin written by Epic and extended it with the appropriate Objective-C - Code.

You can take a look at “LocationServicesIOSImpl.cpp” from the Engine-Source for example-code.

I didn´t know how Objective-C works before: here is a good way to start:

http://cocoadevcentral.com/d/learn_objectivec/

and for LocationService in common here:

https://developer.apple.com/documentation/corelocation/getting_heading_and_course_information

https://developer.apple.com/documentation/corelocation/clheading

Then we can do something like:

    -(void)startUpdatingHeading
    {
        LocManager = [[CLLocationManager alloc] init];
        LocManager.delegate = self;
        
        if([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined)
        {
            //we need to request location services
            //[LocManager requestAlwaysAuthorization];
            [LocManager requestWhenInUseAuthorization];
        }
        if([ CLLocationManager headingAvailable])
        {
            
            LocManager.headingFilter = 5;
            // we also need to deliver LocationUpdates, why? i do not know, but it´s recommended in the apple documentation, maybe it´s a parent service ?
            [LocManager startUpdatingLocation];
            [LocManager startUpdatingHeading];
        }
    }
    -(void)stopUpdatingHeading
    {
        if([ CLLocationManager headingAvailable])
        {
            [LocManager stopUpdatingLocation];
            [LocManager stopUpdatingHeading];
             
            [LocManager release];
            LocManager = nil;
            
        }
    }
/*
     * Callback from the LocationManager when there is an update to our Heading
     */
    -(void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
    {
        if(newHeading.headingAccuracy < 0)
        {
            return;
        }
    
        //use Heading if its valid
        CLLocationDirection theHeading = ((newHeading.trueHeading > 0) ?
                                          newHeading.trueHeading : newHeading.magneticHeading);
        FHeadingServicesData headingData;
        headingData.MagneticHeading = (float)theHeading;


// and broadcast this to Unreal

UHeadingServicesBPLibrary::GetHeadingServicesImpl()->OnHeadingChanged.Broadcast(headingData);

Hope this helps.

1 Like