【问题标题】:PhoneGap device.uuid (VS.) iPad [[UIDevice currentDevice] uniqueIdentifier]PhoneGap device.uuid (VS.) iPad [[UIDevice currentDevice] uniqueIdentifier]
【发布时间】:2012-06-03 19:26:32
【问题描述】:

我正在寻找一种方法来从 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。

有人知道如何做到这一点吗? 提前致谢!

【问题讨论】:

    标签: objective-c ipad cordova uniqueidentifier


    【解决方案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];
    }
    

    【讨论】:

      【解决方案2】:

      uniqueIdentifier 自 iOS 5 起已弃用。您根本不应该再使用它。

      【讨论】:

      • ..因此device.uuid 足以满足您的目的,或者,您可以编写自己的代码来散列设备的功能和信息,并创建一个 JavaScript 函数和 Objective-C 函数来实现这。或者编写一个调用 Objective-C uuid 方法并将结果返回给 JavaScript 的 PhoneGap 插件。
      猜你喜欢
      • 2011-06-03
      • 1970-01-01
      • 1970-01-01
      • 2012-03-12
      • 1970-01-01
      • 2011-02-01
      • 2023-03-10
      • 2013-01-02
      • 2011-01-28
      相关资源
      最近更新 更多