2011-06-20 23 views
0

我無法傳遞UDID的URL在Xcode:通過UDID到URL

[web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://example.com/?udid="+[UIDevice currentDevice].uniqueIdentifier]]]; 

以上不起作用。我該如何解決這個問題?

+1

你是什麼意思「不起作用?」它如何失敗? –

回答

8

級聯是目的C. diferent

做到這一點:

NSString *udid = [UIDevice currentDevice].uniqueIdentifier; 
NSString *string = [NSString stringWithFormat:@"http://example.com/?udid=%@",udid]; 
NSURL *url = [NSURL URLWithString:string]; 
[web loadRequest:[NSURLRequest requestWithURL:url]]; 
+0

我把事情分解成多行,因爲一行很長的行很難讀。 +1雖然:) –

+0

謝謝你的工作! – John

2

你需要正確地構建你的URL字符串... 「+」 在Objective-不連接字符串C。改用-stringWithFormat:等方法。

0

您不能在Objective-C中使用「+」進行字符串連接。它應該是

[NSURL URLWithString: [@"http://www.example.com/?udid=" stringByAppendingString: [UIDevice currentDevice].uniqueIdentifier]]