Sending iphone's [[UIDevice currentDevice] name] over network
I'm trying to send the device name over a network impl开发者_C百科emented with CFNetwork. My application will successfully send the NSString over the simulator, but not on an actual device. The class reference has the properties for this function set at:
@propertyic,readonly,retain) NSString *name
I've tried formatting the final string I intend to use by using stringWithFormat as well as stringByAppendingString but it won't work using either method.
First try to send a a stupid name that you create, like
NSString *nameTest = @"Name of iPad"
If you see this, the problem is not send a NSString, I think this is working for you. Than, you know get the name with this
NSString *name = [[UIDevice currentDevice] name];
Now the bug you can have is: A nill name or name with invalid character, this work for me:
NSArray *toRemove = [NSArray arrayWithObjects:@"'", @"\"", @"<", @">", nil];
for (NSString *currentChar in toRemove) {
name = [name stringByReplacingOccurrencesOfString:currentChar
withString:@""];
}
if ([name isEqualTo:@""]) name = @"no name";
See if this is the problem
精彩评论