John
John

Reputation: 15

passing UDID to url

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

Answers (3)

Caleb
Caleb

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

Diego Torres
Diego Torres

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

Chris R. Donnelly
Chris R. Donnelly

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

Related Questions