iOS插件的Unity在重命名后无法工作



我在我的Assets/Plugins/iOS文件夹中有LocationController.mm文件。它内部的所有功能都可以很好地工作。我将文件和班级重命名为BackgroundController。之后,所有功能都停止工作。

看起来didFinishLaunchingWithOptionsstartUnity方法永远不会调用。如果我从Unity调用_GetLocation()方法,它可以工作,但始终返回所有零。

有没有正确的方法来导入此文件?感谢您的回复。

BackgroundController.mm(ex 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中设置了所有权限。

在我将文件重命名为 BackgroundController.m之后,所有人都开始工作,试图建立构建,出错,然后将其重命名为 BackgroundController.mm

我做了很多事情,所以我不确定我的答案是否合适。

最新更新