UIDevice 属性和 NSLog 的问题

发布于 2024-11-09 09:59:01 字数 1525 浏览 0 评论 0原文

我一直在尝试使用 [[UIDevice currentDevice] ...] 和 NSLog 记录设备参数。尽管尝试了不同的方法,但我总是收到相同的警告。

我得到的警告是:

Passing argument 1 of 'NSLog' from incompatible pointer type

这是我所有的尝试:

1:

NSString *UDID = [[UIDevice currentDevice] uniqueIdentifier];
    NSString *deviceName = [[UIDevice currentDevice] name];
    NSString *deviceModel = [[UIDevice currentDevice] model];

    NSLog("\nDevice UDID: %@\nDevice Name: %@\nDevice Mode:%@\n",UDID, deviceName, deviceModel);

2:

NSString *UDID = (NSString*)[[UIDevice currentDevice] uniqueIdentifier];
    NSString *deviceName = (NSString*)[[UIDevice currentDevice] name];
    NSString *deviceModel = (NSString*)[[UIDevice currentDevice] model];

    NSLog("\nDevice UDID: %@\nDevice Name: %@\nDevice Mode:%@\n",UDID, deviceName, deviceModel);

3:

NSString *UDID = [NSString stringWithFormat:[[UIDevice currentDevice] uniqueIdentifier]];
    NSString *deviceName = [NSString stringWithFormat:[[UIDevice currentDevice] name]];
    NSString *deviceModel = [NSString stringWithFormat:[[UIDevice currentDevice] model]];

    NSLog("\nDevice UDID: %@\nDevice Name: %@\nDevice Mode:%@\n",UDID, deviceName, deviceModel);

4:

NSLog("\nDevice UDID: %@\nDevice Name: %@\nDevice Mode:%@\n",[[UIDevice currentDevice] uniqueIdentifier], [[UIDevice currentDevice] name], [[UIDevice currentDevice] model]);

有人可以帮助我吗?谢谢!

I've been trying to log device parameters using [[UIDevice currentDevice] ...] and NSLog. I always get the same warning despite trying different ways to go about it.

The warning I get is:

Passing argument 1 of 'NSLog' from incompatible pointer type

Here are all my attempts:

1:

NSString *UDID = [[UIDevice currentDevice] uniqueIdentifier];
    NSString *deviceName = [[UIDevice currentDevice] name];
    NSString *deviceModel = [[UIDevice currentDevice] model];

    NSLog("\nDevice UDID: %@\nDevice Name: %@\nDevice Mode:%@\n",UDID, deviceName, deviceModel);

2:

NSString *UDID = (NSString*)[[UIDevice currentDevice] uniqueIdentifier];
    NSString *deviceName = (NSString*)[[UIDevice currentDevice] name];
    NSString *deviceModel = (NSString*)[[UIDevice currentDevice] model];

    NSLog("\nDevice UDID: %@\nDevice Name: %@\nDevice Mode:%@\n",UDID, deviceName, deviceModel);

3:

NSString *UDID = [NSString stringWithFormat:[[UIDevice currentDevice] uniqueIdentifier]];
    NSString *deviceName = [NSString stringWithFormat:[[UIDevice currentDevice] name]];
    NSString *deviceModel = [NSString stringWithFormat:[[UIDevice currentDevice] model]];

    NSLog("\nDevice UDID: %@\nDevice Name: %@\nDevice Mode:%@\n",UDID, deviceName, deviceModel);

4:

NSLog("\nDevice UDID: %@\nDevice Name: %@\nDevice Mode:%@\n",[[UIDevice currentDevice] uniqueIdentifier], [[UIDevice currentDevice] name], [[UIDevice currentDevice] model]);

Can anyone help me out? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

请远离我 2024-11-16 09:59:01

您需要使用 NSString 作为 NSLog 的第一个参数
例如,

NSLog(@"\nDevice UDID: %@\nDevice Name: %@\nDevice Mode:%@\n",UDID, deviceName, deviceModel);

请注意字符串开头之前的“@”

You need to use an NSString as the first argument to NSLog
For example

NSLog(@"\nDevice UDID: %@\nDevice Name: %@\nDevice Mode:%@\n",UDID, deviceName, deviceModel);

Notice the '@' before the start of the string

拥抱影子 2024-11-16 09:59:01

NSLog 采用 NSString 作为格式字符串,而不是 const char*。在字符串前面添加 @

IE:

NSLog(@"\nDevice UDID: %@\nDevice Name: %@\nDevice Mode:%@\n", ....

NSLog takes an NSString as the format string, not a const char*. Prepend your string with a @.

i.e.:

NSLog(@"\nDevice UDID: %@\nDevice Name: %@\nDevice Mode:%@\n", ....
究竟谁懂我的在乎 2024-11-16 09:59:01

NSLog 需要一个 NSString 作为其格式参数。您应该像这样调用 NSLog

NSLog(@"\nDevice UDID: %@", [[UIDevice currentDevice] uniqueIdentifier]);

注意开头的“@” - 这是一个常量 NSString 引用。您正在使用裸 C 字符串。

NSLog requires an NSString as its format argument. You should be calling NSLog like so:

NSLog(@"\nDevice UDID: %@", [[UIDevice currentDevice] uniqueIdentifier]);

Note the "@" at the beginning - that's a constant NSString reference. You're using bare C strings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文