PhoneGap device.uuid(VS.)iPad [[UIDevice currentDevice] uniqueIdentifier]

时间:2012-06-03 19:26:33

标签: objective-c ipad cordova uniqueidentifier

我正在寻找一种从PhoneGap和原生Objective-C环境中从iPad获取设备UUID的方法。问题是PhoneGap只给我一个哈希版本的设备UUID。例如:

1) device.uuid = E0AB7C8C-EFEE-4EB1-9B8F-A543575390A0
2) [[UIDevice currentDevice] uniqueIdentifier] = 75579DE5-98C7-53B6-B2AD-7F348662CB5D

但由于我需要两个值相同,我需要以下解决方案之一 1)如何完全像PhoneGap在Objective-C中那样对[device uniqueIdentifier]进行散列。 2)如何从PhoneGap(JavaScript)获取原始(非散列)设备的UUID。

有人知道如何实现这一目标吗? 提前谢谢!

2 个答案:

答案 0 :(得分:2)

自iOS 5起,

uniqueIdentifier已被弃用。您根本不应再使用它。

答案 1 :(得分:1)

由于PhoneGap是开源的,你可以看看它是如何自己生成UUID的。

以下是PhoneGap使用的方法(从1.7.0复制)。我还复制了Apache许可证,以防我应该这样做。

/*
 Licensed to the Apache Software Foundation (ASF) under one
 or more contributor license agreements.  See the NOTICE file
 distributed with this work for additional information
 regarding copyright ownership.  The ASF licenses this file
 to you under the Apache License, Version 2.0 (the
 "License"); you may not use this file except in compliance
 with the License.  You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing,
 software distributed under the License is distributed on an
 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 */

- (NSString*) uniqueAppInstanceIdentifier
{
    // full path to the app folder
    NSString* bundlePath = [[[NSBundle mainBundle] bundlePath]
        stringByDeletingLastPathComponent];

    // return only the folder name (a GUID)
    return [bundlePath lastPathComponent];
}