我無法傳遞UDID的URL在Xcode:通過UDID到URL
[web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://example.com/?udid="+[UIDevice currentDevice].uniqueIdentifier]]];
以上不起作用。我該如何解決這個問題?
我無法傳遞UDID的URL在Xcode:通過UDID到URL
[web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://example.com/?udid="+[UIDevice currentDevice].uniqueIdentifier]]];
以上不起作用。我該如何解決這個問題?
級聯是目的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]];
我把事情分解成多行,因爲一行很長的行很難讀。 +1雖然:) –
謝謝你的工作! – John
你需要正確地構建你的URL字符串... 「+」 在Objective-不連接字符串C。改用-stringWithFormat:
等方法。
您不能在Objective-C中使用「+」進行字符串連接。它應該是
[NSURL URLWithString: [@"http://www.example.com/?udid=" stringByAppendingString: [UIDevice currentDevice].uniqueIdentifier]]
你是什麼意思「不起作用?」它如何失敗? –