2017-02-22 4 views
0

Ich hatte LocationController.mm Datei in meinem Ordner Assets/Plugins/iOS. Alle Funktionen darin funktionierten perfekt. Ich habe beide Dateien und Klassen in BackgroundController umbenannt. Danach funktionierten alle Funktionen nicht mehr.Einheit für iOS-Plugin funktioniert nicht nach dem Umbenennen

Wie es aussieht didFinishLaunchingWithOptions und startUnity Methoden nie aufrufen. Wenn ich _GetLocation() Methode von Unity aufrufen, funktioniert es, aber gibt immer nur Nullen zurück.

Gibt es einen geeigneten Weg, diese Datei zu importieren? Danke für die Antwort.

BackgroundController.mm (ex LocationController.mm) Datei:

#import <Foundation/Foundation.h> 
#import <CoreLocation/CoreLocation.h> 

#import "UnityAppController.h" 

@interface BackgroundController : UnityAppController 
<CLLocationManagerDelegate>{ 
    CLLocationManager *locationManager; 
} 
@end 

extern bool _unityAppReady; 

static float latitude = 0; 
static float longitude = 0; 
static float horizontalAccuracy = 0; 

@implementation BackgroundController{ 
} 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes: UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge categories:nil]; 
    [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; 

    return [super application:application didFinishLaunchingWithOptions:launchOptions]; 
} 

-(void) startUnity:(UIApplication*) application { 
    [self startStandardUpdates]; 

    [super startUnity:application]; 
} 

- (void)startStandardUpdates 
{ 
    // Create the location manager if this object does not 
    // already have one. 
    if (nil == locationManager) 
     locationManager = [[CLLocationManager alloc] init]; 

    locationManager.delegate = self; 
    locationManager.desiredAccuracy = kCLLocationAccuracyBest; 

    // Set a movement threshold for new events. 
    locationManager.distanceFilter = 10; // meters 

    [locationManager requestAlwaysAuthorization]; 

    [locationManager startUpdatingLocation]; 
} 

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { 
    // updating location values 
} 

// other methods implementation 

@end 

extern "C" const char* _GetLocation() 
{ 

    NSString *location = [NSString stringWithFormat:@"%f,%f,%f",latitude,longitude,horizontalAccuracy]; 

    char* ret = (char*)::malloc(location.length + 1); 
    ::memcpy(ret, [location UTF8String], location.length); 
    ret[location.length] = 0; 

    return ret; 
} 

IMPL_APP_CONTROLLER_SUBCLASS(BackgroundController) 

Nach Build auf Xcode-Datei in Libraries/Plugins/iOS Ordner wie zuvor befindet.

Ich habe versucht, ReimportAll Dateien, aber das hat nicht geholfen.

Wenn ich alle wieder in LocationController umbenenne, funktioniert immer noch nichts.

Ich habe alle Berechtigungen in auch gesetzt.

Antwort

0

Alles wurde Arbeit, nachdem ich die Datei in BackgroundController.m umbenannt, versucht zu bauen, bekam Fehler und dann wieder in BackgroundController.mm umbenannt.

Ich habe viel gemacht, also bin ich mir nicht sicher, ob meine Antwort richtig ist.

Verwandte Themen