0

The following code, while not necessarily pretty, worked absolutely fine in iOS 4.1 (returned an NSString with formatted HTML with the passed URL). In iOS 4.2.1, however, the function always returns nil if using stringWithFormat. NSLog shows the contents of embedHTML are correct, but the value of *html is always nil.

Any help is appreciated.

....
NSString *html = [self getHTML:urlString1];
....

- (NSString *)getHTML:(NSString *) url {

NSString *embedHTML = [NSString stringWithFormat:@"<html><head>\
<style type=\"text/css\">\
body {\
background-color: transparent;\
color: white;\
</style>\
</head><body style=\"margin:0\">\
<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
width=\"111\" height=\"116f\"></embed>\
</body></html>", url];

NSLog(@"Log: %@", embedHTML);

return embedHTML;

}

MathieuF
  • 3,130
  • 5
  • 31
  • 34
voodoobilly
  • 405
  • 7
  • 18

2 Answers2

0

Try this

NSString *html = [NSString stringWithFormat:@"<html><head>\
                       <style type=\"text/css\">\
                       body {\
                       background-color: transparent;\
                       color: white;\
                       </style>\
                       </head><body style=\"margin:0\">\
                       <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
                       width=\"111\" height=\"116f\"></embed>\
                       </body></html>", urlString1];
ipraba
  • 16,485
  • 4
  • 59
  • 58
0

Put quotes around each split line. You shouldn't need the backslash.

This question is similar, for C++, but I think the same rules apply to Objective C

Splitting C++ Strings Onto Multiple Lines (Code Syntax, Not Parsing)

Community
  • 1
  • 1
TomSwift
  • 39,369
  • 12
  • 121
  • 149
  • Thanks for the suggestion. Turns out there was actually an issue in the string I was attempting to insert that was throwing everything off. To make a short story long, it's fixed. – voodoobilly Nov 28 '10 at 13:10