我的// example JSON
var j = '{"$id":"0","name":"Parent","child":{"$id":"1", "name":"Child","parent":{"$ref":"0"}},"nullValue":null}'
function parseAndResolve(json) {
var refMap = {};
return JSON.parse(json, function (key, value) {
if (key === '$id') {
refMap[value] = this;
// return undefined so that the property is deleted
return void(0);
}
if (value && value.$ref) { return refMap[value.$ref]; }
return value;
});
}
console.log(parseAndResolve(j));
文件夹中有LocationController.mm
个文件。其中的所有功能都完美无缺。我将文件和类重命名为Assets/Plugins/iOS
。之后,所有功能都停止了工作。
看起来BackgroundController
和didFinishLaunchingWithOptions
方法永远不会调用。如果我从Unity调用startUnity
方法,它可以工作,但总是返回全零。
有没有正确的方法导入此文件?谢谢你的回复。
_GetLocation()
(ex BackgroundController.mm
)档案:
LocationController.mm
构建在Xcode文件之后,如前所述位于#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)
文件夹中。
我尝试了Libraries/Plugins/iOS
个文件,但这没有帮助。
当我将所有内容重命名为ReimportAll
时,仍然无效。
我也在LocationController
设置了所有权限。
答案 0 :(得分:0)
我将文件重命名为BackgroundController.m
,尝试进行构建,出错,然后重命名为BackgroundController.mm
。
我做了很多,所以我不确定我的回答是否合适。