문제

I am sending HTML formatted email from within the iPhone app. I am reading HTML file stored within the application package.

Now, I want to change certain text within the HTML file, I.e. there is name,email and phone which will change depending on certain selections by the user in the app.

How to add these varying parameters to HTML file content?

Please help.

Thanks

도움이 되었습니까?

해결책

Something like this may work for you:

NSString *htmlPath = [[NSBundle mainBundle] pathForResource:@"yourHtml" ofType:@"html"];

NSError *error = nil;

NSString *inputHtml = [[NSString alloc] initWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:&error];

NSString *nameParsedHtml = [inputHtml stringByReplacingOccurrencesOfString:@"Name:" withString:[NSString stringWithFormat:@"Name: %@", self.nameField.text]];

NSString *emailParsedHtml = [nameParsedHtml stringByReplacingOccurrencesOfString:@"Email:" withString:[NSString stringWithFormat:@"Email: %@", self.emailField.text]];

NSString *outputHtml = [emailParsedHtml stringByReplacingOccurrencesOfString:@"Phone:" withString:[NSString stringWithFormat:@"Phone: %@", self.phoneField.text]];

NSLog(@"Output html string is: %@", outputHtml);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top