我在我的Assets/Plugins/iOS
文件夾中有LocationController.mm
文件。它內部的所有功能都很完美。我將裏面的文件和類都重命名爲BackgroundController
。之後,所有功能停止工作。Unity for iOS插件重命名後無法正常工作
看起來像didFinishLaunchingWithOptions
和startUnity
方法永遠不會調用。如果我從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
中設置的所有權限。