WebView doesn't load my HTML String in iPhone - iphone

This doesn't load my HTML string in the WebView.
NSString *htmlString = #"<html><body><h1>My First Heading</h1><p>My first paragraph.</p></body></html>";
//I have a very large HTML content here.. For sample I have given a small content
[teaserWebView loadHTMLString:htmlString baseURL:nil];
Do I need to use some encoding? Any help will be appreciated.
Thanks

Edit: Solution found in comments on question.
In your large HTML, Replace % with %25.
I really don't know if that will help, but it is required in Android WebView. All encoding is automatic except it does not know whether or not to encode %.
There is a better way to encode everything, but it is not required and I have no clue how to do it in iPhone.
See this page for more info: http://www.w3schools.com/TAGS/ref_urlencode.asp
Also you may want to look up "URL Encode iPhone".
I know this is not a URL, but in Android it gets converted to a data: URL where all the data is in the URL. It likely works the same way in iPhone.

Related

Filepicker.io pick epub mimetype

I've been working with the filepicker api for the past day or so - trying to wrap my head around mimetype validation when using the pick method. I'd like to only support uploading epub files, which have the mimetype : 'application/epub+zip'. However, whenever I use this as the only supported mimetype in filepicker, I get the following error :
The page can only support a application/epub zip/*
It seems to be interpreting the '+' inside of the string as a space. Any advice on how to fix this, or validate epub files properly would be appreciated!
Edit : I found a way around this by using 'extension' instead - and adding {extension : '.epub'}. This will work, as I can just set the maxSize to be some reasonable number, and perform some validation server-side (and deleting the file from s3 if it isn't actually an epub). If someone figures out how to do it properly with the mimetype that would be awesome though!
Glad you got it to work with extension, one way with mimetype might be to urlencode the + to be %2B

Help to get rid of > < (html tags) in woot.com API?

so i am making a woot app, and i am using the API. in the description section of the xml rss file, there are always a lot of > and < (less than and greater than < >) surrounding the html tags. i realize they did this so as not to confuse them with the xml tags, but it is kind of annoying. i cant just put the code that i get from the xml file right into a webview, because it displays the less than and greater than signs, and does not actually do the tags. is there any way to get rid of this eaisily? or do i just have to make a loop that goes through all of the code, changing the </tr> to </tr>? i am just wondering how other people have gotten around this problem, or if there is some easy way to do it that i just dont know about. thanks
The content is encoded and you just need to decode it--once you do that it should just render like regular html. I would try to do that first before doing any kind of replace. I'm not an iphone developer but maybe this link can help.
The xml rss file that you are looking at has HTML encoded inside of XML. All you need to do is use an existing XML library for the iPhone such as NSXMLParser or GDataXML and you will not have to worry about decoding.

iPhone: XML Parsing Problem?

I have some XML that looks like the following sample:
<INLINE>
<IMG LINKTEXT="خدمات ديني يقيني" NUMOFCOLOUMNS="9" NUMOFROWS="20">RamadanPortal</IMG>
</INLINE>
When I tried to parse the above XML using NSXMLParser, I'm getting the LINKTEXT response as U062e\U062f.
How can I get the exact Arabic text instead of Unicode characters? Thanks in advance.
You need to download the file in the correct encoding. There's plenty of documentation on this on the apple website (developer docs), but since you haven't supplied a code example I can't point you at the exact one.

How parse html string in iphone

i m using php file for using data in my application,
in this file i post data on the server and if i get the data from the server
then it is in html formate.
so problem is that i have a string with html tags how i use data in that string.
how i extract data from html string.
Use NSXMLParser class. it works for HTML too. There are three useful delegate methods.
If your HTML out put is some simple data - may be you can write some simple NSString parser your self like 'markhunte' mentioned, if you have large complex data in HTML then you have to go for some open source parsers.
Cocoa does not provide HTML parser, Forum discussion claims in some case XML parser itself work for you, but I never go it working for my data.
In my case I had very simple TAG which I had handled using my own parser using NSString.
I have used the code from --> Flatten-html-content-ie-strip-tags-cocoaobjective-c.
There are also examples of its use on SO.
Just use NSScanner, it is great for searching in between tags that are permanent. If you post some page code I help you set up the scanner.

Display local image in iPhone HTML mail

In my app, I am composing an HMTL email message with the 3.0+ MFMailComposeViewController.
To do this, I created an HTML file, with some placeholders.
In my code, I read the HTML file, and with replaceOccurrencesOfString, I replace the placeholders with data from the app.
In that way, I compose the body of the email I want to send out.
This is all working very nicely, except for the fact, that in my HTML file, I have an <img src='imageplaceholderpath' /> tag.
Somehow, I cannot figure out, with what I should replace this imageplaceholderpath, in order to refer to an image that resides in my app.
Is this a valid approach at all, and if so, what would be the syntax/logic behind the path I should put there?
I do appreciate your insights!
Regards
Sjakelien
Unfortunately this is not supported by the iPhone 3.x APIs.
http://developer.apple.com/iphone/library/documentation/MessageUI/Reference/MFMailComposeViewController_class/Reference/Reference.html
It would require Content-ID: to be part of the attachment subpart but it is not.
- (void)addAttachmentData:(NSData*)attachment mimeType:(NSString*)mimeType fileName:(NSString*)filename
Note that using data: URIs won't work across all mail clients. Those that use IE as a rendering engine don't support it at all unless IE8 is installed, and even then, according to Wikipedia, data: URIs are limited to 32 KB maximum.
The very simplest way to get this to work is to put the image on your own server somewhere, and reference it using a full http:// URI. If you can't do that for some reason (maybe the image is generated as part of using your app), then you can try attaching the image as a MIME sub-part and referencing it from the HTML.
My mail client doesn't load remote images automatically, but some spam still has images when I open it. This is how it works:
Attach an image to your mail as suggested by yonel. Somehow you need to also add a Content-ID: header to the sub-part. The contents of this header are then used as the src attribute on your image. My spam message looks like this in the HTML:
<img src="cid:image001.jpg#01CACC43.7035CE50">
The attachment sub-part looks like:
Content-Type: image/jpeg;
name="image001.jpg"
Content-Transfer-Encoding: base64
Content-ID: <image001.jpg#01CACC43.7035CE50>
Looking at the documentation for addAttachmentData:mimeType:fileName:, my guess is that you won't be able to get this to work and will have to consider sending the email using raw SMTP.
I found this post, that answers most of my questions: http://www.iphonedevsdk.com/forum/iphone-sdk-development/25021-embedding-image-email-body.html.
I don't think you can embed the images as part of the email in the way a normal email client would. However it seems that you can include the image data directly in the HTML as base64 encoded data. This is quite a non-standard way of doing things, so the email might not display perfectly on all email clients.
See this question for more, and the sample code on this forum post
I don't know if the HTML format is a must have for you, but actually embedding an image in an email can be achieved without using HTML, just with image as attachment.
Just have a look at the way it is achieved here :
http://iphone-dev-tips.alterplay.com/2009/11/attaching-image-of-uiview-to-email.html
the crucial part is this :
// ATTACHING A SCREENSHOT
NSData *myData = UIImagePNGRepresentation(screenshot);
[controller addAttachmentData:myData mimeType:#"image/png" fileName:#"route"];
You get the PNG representation of your UIImage (as NSData) and you attach it yo your email.