Reputation: 15
I am having trouble passing the UDID to a url in xcode:
[web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://example.com/?udid="+[UIDevice currentDevice].uniqueIdentifier]]];
The above does not work. How can I fixed that?
Upvotes: 0
Views: 2150
Reputation: 125037
You'll need to construct your URL string properly... "+" doesn't concatenate strings in Objective-C. Use a method like -stringWithFormat:
instead.
Upvotes: 2
Reputation: 5308
The concatenation is diferent in Objective C.
DO THIS:
NSString *udid = [UIDevice currentDevice].uniqueIdentifier;
NSString *string = [NSString stringWithFormat:@"http://example.com/?udid=%@",udid];
NSURL *url = [NSURL URLWithString:string];
[web loadRequest:[NSURLRequest requestWithURL:url]];
Upvotes: 8
Reputation: 3135
You cannot do string concatenation with a "+" in Objective-C. It should be
[NSURL URLWithString: [@"http://www.example.com/?udid=" stringByAppendingString: [UIDevice currentDevice].uniqueIdentifier]]
Upvotes: 0