开发者

Problems with UIDevice properties and NSLog

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 c开发者_Go百科urrentDevice] 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!


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


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", ....


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜