Rest 无Unity SDK的纸板QR扫描
我一直在试图找出如何扫描和使用纸板设备提供的二维码,而不需要使用Unity API。我已经为使用Obj-c的iOS设备的基于SceneKit的虚拟现实编写了SCN-VR,我希望扫描二维码也能使配置文件的设置更简单Rest 无Unity SDK的纸板QR扫描,rest,qr-code,google-cardboard,Rest,Qr Code,Google Cardboard,我一直在试图找出如何扫描和使用纸板设备提供的二维码,而不需要使用Unity API。我已经为使用Obj-c的iOS设备的基于SceneKit的虚拟现实编写了SCN-VR,我希望扫描二维码也能使配置文件的设置更简单 我看到了对goo.gl/pdNRON的二维码扫描,这导致了一个关于如何下载谷歌硬纸板应用程序的页面,但谷歌硬纸板应用程序将下载实际的配置文件是什么HTTP服务?二维码可以通过谷歌的协议缓冲区()解析。从代码扫描的缩短URL被重定向到包含p=查询字段中实际信息的URL。例如,您的URL(
我看到了对goo.gl/pdNRON的二维码扫描,这导致了一个关于如何下载谷歌硬纸板应用程序的页面,但谷歌硬纸板应用程序将下载实际的配置文件是什么HTTP服务?二维码可以通过谷歌的协议缓冲区()解析。从代码扫描的缩短URL被重定向到包含p=查询字段中实际信息的URL。例如,您的URL(goo.gl/pdNRON)重定向到(在浏览器中显示为纸板下载站点)。您需要的字符串是以CgxNYXR开头的长字符串。该字段是base64编码的 协议缓冲区定义文件位于。一旦构建了Protocol Buffers编译器(protoc,来自上面的教程链接),只需在CardboardDevice.proto上运行它,并在项目中包含output.cc和.h文件。发送解码数据后,您可以通过DeviceParams类型访问信息 用于构建协议缓冲区库并将其包含在iOS项目中:。 或者,如果生成/链接库时遇到问题,请尝试以下方法: 以下是一些让您开始学习的代码:
// Retrieve HEAD only (don't want the whole page)
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@", myURL]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:10.0f];
[request setHTTPMethod:@"HEAD"];
// Start the request
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
if (connectionError) {
NSLog(@"%@", [connectionError localizedDescription]);
} else {
// Find the p attribute
NSArray *comps = [[[response URL] query] componentsSeparatedByString:@"&"];
for (NSString *comp in comps) {
NSArray *subComps = [comp componentsSeparatedByString:@"="];
if ([subComps count] == 2 && [subComps[0] isEqualToString:@"p"]) {
NSString *base64 = subComps[1];
// Replace _ with /, - with +, and pad with = to multiple of 4
base64 = [base64 stringByReplacingOccurrencesOfString:@"_" withString:@"/"];
base64 = [base64 stringByReplacingOccurrencesOfString:@"-" withString:@"+"];
base64 = [base64 stringByPaddingToLength:(([base64 length]+3)/4)*4 withString:@"=" startingAtIndex:0];
// Decode from base 64
NSData *decodedData = [[NSData alloc] initWithBase64EncodedString:base64
options:NSDataBase64DecodingIgnoreUnknownCharacters];
// Get the device parameters
DeviceParams deviceParams;
deviceParams.ParseFromArray([decodedData bytes], (int)[decodedData length]);
// Do stuff with deviceParams
// eg deviceParams.inter_lens_distance()
break;
}
}
}
}];
FWIW,如果您使用Swift并且不需要protobuf依赖项,那么您可以使用它来进行解码