【问题标题】:I'm making an IOS application, how do I make the application send me the UDID of the device its on?我正在制作一个 IOS 应用程序,如何让应用程序向我发送设备的 UDID?
【发布时间】:2013-09-07 03:44:17
【问题描述】:

我目前正在开发 IOS 应用程序,出于安全考虑,我想知道如何让应用程序将设备“UDID”发送到服务器。 所以基本上我需要知道如何让设备“获取” udid,然后获取 udid 并将其作为“请求”发送到服务器。

如果 UDID 已在 MYSQL 数据库中“注册”,则服务器将发回确认信息。

除了了解如何获取 udid 之外,我可能还需要其他帮助来设置 mysql 数据库:$

谢谢!

【问题讨论】:

  • 什么是“安全目的”?

标签: mysql iphone ios


【解决方案1】:

您可以使用以下方法获取 iOS 设备的 UUID:CFUUIDRef udid = CFUUIDCreate(NULL); NSString *udidString = (NSString *) CFUUIDCreateString(NULL, udid);

(Apple 不喜欢你使用 UDID)。

至于将其发布到服务器,我建议使用 JSON 发布方法,并记录成功。一个好的 JSON 库是 SBJson,可以在 here 找到。您需要创建一个 HTTP 帖子,获取响应数据,并使用 SBJson 库来解析响应。

编辑:或者代替 SBJson,正如 Carbonic acid 所指出的那样,您可以使用 NSJSONSerialization。此外,正如 Naz Mir 所指出的,使用了新的 UUID 方法。

【讨论】:

  • 您不再需要SBJSON。 iOS4+ 有NSJSONSerialization 类。
【解决方案2】:

编辑:

[[[UIDevice currentDevice] identifierForVendor] UUIDString] 没有像我所说的那样被弃用。请通过以下链接获取信息。

如上所述获取 UDID NSString *uuididentifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];已弃用且 Apple 不再允许。 如果您的目标是唯一标识设备,您可以使用 SecureUDIDOpenUDID

我曾经在我们的一个应用程序中使用过 OpenUDID,使用它就像 -

#import "OpenUDID.h"

[OpenUDID setOptOut:NO];
self.openUDID = [OpenUDID value];

一旦您获得所需的值,将其发送到服务器就很简单了。您可以使用AFNetworking 等iOS 网络库来发送和接收数据。例如,

#import "AFHTTPRequestOperation.h"

NSURL *url = [NSURL URLWithString:@"Your sever URL"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
NSString *postString = [NSString stringWithFormat:@"&UDID=%@", self.
[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPMethod:@"POST"];
AFHTTPRequestOperation *httpOperation = [[AFHTTPRequestOperation alloc] initWithRequest:request];

[httpOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *httpOperation, id responseObject) {

        //handle server response here
        NSLog(@"%@", [httpOperation responseString]); //this contains the servers response

}failure:^(AFHTTPRequestOperation *httpOperation, NSError *error) {          

        //handle server errors here
        NSLog(@"error: %@", [httpOperation error]);
}];

【讨论】:

  • -1 identifierForVendor 未被弃用。您应该查看已链接的页面。两者都推荐使用identifierForVendoradvertisingIdentifier
猜你喜欢
  • 1970-01-01
  • 2016-04-04
  • 1970-01-01
  • 1970-01-01
  • 2012-09-10
  • 1970-01-01
  • 2011-06-23
  • 2015-05-31
  • 1970-01-01
相关资源
最近更新 更多