2016-05-18 5 views
0

Ich mag den ID-Nummer Teil von einer App-Store-URL extrahieren, beispielsweise nach zwei App-Store-Urls: https://itunes.apple.com/app/apple-store/id882456583?pt=63826800&ct=%E5%AE%A3%E4%BC%A0%E8%B4%B4001&mt=8ios wie man den ID-Nummer Teil aus einer App-Store-URL extrahiert?

https://itunes.apple.com/app/juan-pi-zhe-kou-shou-ji-shang/id639388447?mt=8&uo=4

Ich mag würde die Zahl nach "id" extrahieren, dh 882456583 und 639388447. Wer weiß, wie man das macht? Vielen Dank.

Antwort

2

Versuchen Sie, diese

Swift:

let appStoreUrl = NSURL(string: "https://itunes.apple.com/app/juan-pi-zhe-kou-shou-ji-shang/id639388447?mt=8&uo=") 
let appId = appStoreUrl?.lastPathComponent?.stringByReplacingOccurrencesOfString("id", withString: "") 

Objective C:

NSURL *appStoreUrl = [NSURL URLWithString:@"https://itunes.apple.com/app/juan-pi-zhe-kou-shou-ji-shang/id639388447?mt=8&uo="]; 
NSString *appId = [appStoreUrl.lastPathComponent stringByReplacingOccurrencesOfString:@"id" withString:@""]; 

Ergebnis:

enter image description here

2

Was Sie erwarten, ist dies

NSURLComponents *components = [NSURLComponents componentsWithURL:[NSURL URLWithString:@"https://itunes.apple.com/app/apple-store/id882456583?pt=63826800&ct=%E5%AE%A3%E4%BC%A0%E8%B4%B4001&mt=8"] resolvingAgainstBaseURL:NO]; 
NSLog(@"id = %@",[[[components valueForKey:@"path"] componentsSeparatedByString:@"/"] lastObject]); 

in Protokollen Sie param erforderlich haben werde.

+0

Das gibt so etwas wie: " { name = mt, value = 8} ", brauche ich die App-ID, nicht diese Parameter – user2053760

+0

willst du nur dieses' id639388447' richtig? oder 63826800? – Rajesh

+0

siehe meine Bearbeitung wird Ihnen den Schlüssel geben – Rajesh

Verwandte Themen