2017-02-22 103 views
0

我在我的Assets/Plugins/iOS文件夾中有LocationController.mm文件。它內部的所有功能都很完美。我將裏面的文件和類都重命名爲BackgroundController。之後,所有功能停止工作。Unity for iOS插件重命名後無法正常工作

看起來像didFinishLaunchingWithOptionsstartUnity方法永遠不會調用。如果我從Unity調用_GetLocation()方法,它可以工作,但總是返回全零。

是否有任何正確的方法導入此文件?感謝回覆。

BackgroundController.mm(前LocationController.mm)文件:

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

上的Xcode文件構建位於Libraries/Plugins/iOS文件夾作爲較早後。

我試圖ReimportAll文件,但沒有幫助。

當我重新命名爲LocationController時,仍然無效。

我也擁有在info.plist中設置的所有權限。

回答

0

我將文件重命名爲BackgroundController.m後,所有工作都開始工作,試圖進行構建,出錯,然後重新命名爲BackgroundController.mm

我做了很多,所以我不敢肯定,如果我的答案是正確的。