UIDevice 属性和 NSLog 的问题
我一直在尝试使用 [[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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要使用 NSString 作为 NSLog 的第一个参数
例如,
请注意字符串开头之前的“@”
You need to use an NSString as the first argument to NSLog
For example
Notice the '@' before the start of the string
NSLog
采用 NSString 作为格式字符串,而不是const char*
。在字符串前面添加@
。IE:
NSLog
takes an NSString as the format string, not aconst char*
. Prepend your string with a@
.i.e.:
NSLog
需要一个NSString
作为其格式参数。您应该像这样调用NSLog
:注意开头的“@” - 这是一个常量
NSString
引用。您正在使用裸 C 字符串。NSLog
requires anNSString
as its format argument. You should be callingNSLog
like so:Note the "@" at the beginning - that's a constant
NSString
reference. You're using bare C strings.