カスタムIPアドレスを既存のURLIPアドレスに置き換えようとしています。私のIPアドレスを既存のIPに置き換えるにはどうすればよいですか。以下のコードスニペットを見つけてください
- (IBAction)btnSubmit:(UIButton *)sender {
NSString *ipAdd = [_txtIPAddress text];
NSLog(@"My entered IP Address is %@", ipAdd);
NSLog(@"Current pointing server value is %@", [ConnManager activeEndpoint]);
NSLog([App appDelegate].isConfigured ? @"Yes" : @"No");
NSArray *listItems = [[ConnManager activeEndpoint] componentsSeparatedByString:@"/"];
ConnManager *conn = [[ConnManager alloc] init];
NSMutableString *configuredUrl = nil;
[configuredUrl setString:@""];
for ( NSInteger i =0; i < listItems.count; i++) {
if(i != 2) {
NSMutableString * arrayElement = [(NSMutableString*)listItems objectAtIndex:i];
NSMutableString *str = [NSMutableString stringWithFormat: @"%@/", arrayElement];
[configuredUrl appendString:str];
} else {
NSMutableString *configstr = [NSMutableString stringWithFormat: @"%@", ipAdd];
NSLog(@"ConfigString %@", configstr);
//How to replace the my ip address with the array index[2]
configuredUrl = [configuredUrl stringByAppendingFormat:configstr];
NSLog(@"Configured Url after apppending %@", configuredUrl);
前もって感謝します
この短いバージョンを試してください、それは行の後のすべてを置き換えます NSLog([App appDelegate].isConfigured ? @"Yes" : @"No");
NSMutableArray *listItems = [[[ConnManager activeEndpoint] pathComponents] mutableCopy];
listItems[2] = ipAdd;
NSString *configuredUrl = [NSString pathWithComponents:listItems];
NSLog(@"%@", configuredUrl);
または、activeEndpoint
がURLの場合は、さらに簡単です
NSURL *url = [NSURL URLWithString:[ConnManager activeEndpoint]];
NSString *configuredURL = [[[NSURL alloc] initWithScheme:[url scheme] host:ipAdd path:[url path]] absoluteString];
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加