Web search in an iPhone app - iphone

I've got experience in C/C++ and am trying to now learn Objective-C for iPhone development. I have very little web design experience.
I'm trying to create an app for a friend's site that accesses a search feature from a website and then display the results in a UITableView. For example, (this isn't the site I'll be using, but...) using the stackoverflow search function and then being able to format the results (https://stackoverflow.com/search?q=iphone+web+search) in cells. I'd like to leave out the rest of the content on the page.
I've only been able to find info about reading xml or rss search results. Otherwise, I could use UIWebView, but that displays the entire site. Are there other classes that I should look into for doing this? Any help would be very, very much appreciated!

The iPhone SDK doesn't include Cocoa libraries for parsing HTML. Just NSXMLParser, which isn't a good tool for what you want to do. (It will choke on valid HTML that isn't valid XML.)
This page is probably a good first place to look. The author says, "For scraping/reading a webpage, XPath is the best choice. It is faster and less memory intensive then NSXMLParser, and very concise. My experience with it has been positive."

Related

Parse BBCode in an iOS app

I'm writing an app for a forum. I can get the posts as HTML but I need to do lots of custom things with the posts as I'm not displaying it in UIWebView but natively as rich text (custom handling of [youtube][/youtube] tags). So I am instead getting the much cleaner BBCode output of the posts.
This tutorial seems to fit my needs well enough, however there are some obvious problems with it. On is that if the user types mis-formed BBC I get back bad HTML. Leaving out the closing [/b] as an example.
I am thinking I may just need to loop through the outputted HTML and track if there is an unclosed tag at the end, however I was hoping that there might be a better way to parse BBCode on the iPhone.
Also, lastly I know that is probably the wrong approach (outlined above) but every stack overflow question I've found on BBCode parsing has said not to reinvent the wheel and just use an existing PHP library. But, of course, this is an iOS app so I can't use any code written in PHP.
The question is, what is the best way to parse BBCode on iOS (and if there isn't a library or example available then is there a tutorial on writing a good quality one yourself)?

How to Delete nodes from HTML in iOS

What I am trying to do is to load a webpage into in a UIWebView. The problem is that I need to do some preprocessing on the html before displaying it in the web view.
The UIWebview loadHTMLString is quiet slow when the html is big. I don't need to display the full page therefore i am trying to remove some html nodes before displaying it in the web view to speed up the loading time.
I don't think using regex for that is a wise idea. I checked out NSXMLParser and TFHPPLE but I couldn't find any way to remove nodes from the html tree using an XPath or something.
I know I could do that using Javascript but that won't solve my problem. I also don't have no control on the website so I can't edit in the webpage itself.
Is there something as easy as deleteNodeUsingXPath or something :)
Cheers and thanks a lot for your help in advance.
One possibility solution: do a proxy website which strips out unwanted stuff. The iphone accesses the proxy website URL. The proxy website loads from the original website, strips out unwanted stuff, and replies with the remaining stuff.
There is a tool called Objective-C-HTML-Parser that will do what you are looking for. The documentation is thorough, and the implementation is pretty straight-forward.
Basically, you take your HTML string and make an HTMLParser object that you can then manipulate however you want. It is a very powerful library that basically lets you do whatever you want with HTML with easy-to-use Objective-C APIs.
Good luck!

How do I build a wiki into an iPhone app?

I want to build an iPhone app that is really a wrapper around a wiki. Specifically, I have some static reference content that can be represented by a hyperlinked set of pages and want to build an app that will provide a nice interface over this content, including search, bookmarking, and annotating. I'm wondering what the best approach is for building something like this.
(I'm spent a fair bit of time googling for answers but pretty much every combination of search terms I can think of returns links to wikis, not links about putting a wiki into an app).
Are there libraries out there for handling wiki content (rendering, navigating links etc.)? I imagine I could just represent my content as a set of local HTML pages and point the web browser control at these but that doesn't seem right. Any ideas on how best to approach this in the iOS world?
Thanks in advance!
Try looking at TWedit, it is a wrapper for the excellent TiddlyWiki which is a single file WIKI built around JavaScript and HTML. TW is very powerful and well supported with many plugins available.

Best practices for parsing HTML from Wikipedia for iPhone viewing?

I am building an iPhone Wikipeida game app, that requires modifying the default Wiki HTML a little bit (mostly simplifying the page).
So far I am directly downloading the HTML output from en.wikipedia.org/wiki/Article_Foo to a python Google App Engine, and then modify its CSS and HTML structure, cache it, and finally output to iPhone. It works but I find this method quite tedious, there must be a better method?
Please note that I use App Engine not just for parsing the Wiki, but the game also requires it to keep the stores...etc, hence not a overkill. Also, I would prefer doing all the work with python on App Engine, to keep the iPhone client as thin and mobile as possible (XML on iPhone is a big no fun)
Thanks a lot.
=======
Nick mentions why not use the mobile Wiki which already optimizes for iPhone. However, the issue is that it goes down quite frequently (every couple weeks or so), also its HTML structure changes quite frequently too.
You can use the MediaWiki API to download the markup text and use some API tools for Python that could make the process/modify work easier.
Caching and outputting to iPhone is fine. I believe there is not much to simplify here.
Why not just fetch the mobile version of the page from http://en.m.wikipedia.org/? This is already formatted for mobile devices.
You can set up your own copy of the server used by m.wikimedia.org:
http://github.com/hcatlin/wikimedia-mobile
It's written in Ruby, but this shouldn't be an issue if your app just uses the HTML output.

Is there a good iphone sdk documentation site that provides good examples / common usage?

The problem? I look up stuff in the xcode documentation and find very useful lists of objects, methods, etc... But then I still have to go somewhere else to find useful example code of how to use that object. For example, I looked up NSNumber yesterday and found all of the neat stuff it can do, but I still had no clue how to use it. That's just an example. I'm sure I could read the objective c pdf front to back and learn something there (which I plan on doing) but what about later? When I'm looking up some UIKit object? Do I have to go find a tutorial each time (or lately, I just ask StackOverflow and you guys take care of me).
Is there a part of the apple website / xcode documentation that shows the example code I'm looking for?
Is there a wiki site out there or something that has what I'm looking for? (I just tried a simple google search "iphone sdk wiki". this site could be good. iphone sdk wiki . I'll check it out. Anyone else have one they like? )
This is also sort of a mild complaint to Apple. Why not a section on each code definition page that shows usage?
I've found the sample code section on Apple's iPhone Developer Connection be extremely useful not only for samples of complete applications but also a best practices source. Going through the code of The Elements, for example, will expose you to how to use particular classes as well as how to structure your code. It is a wonderful example of how to create a non-trivial iPhone app.
Look in developer.apple.com/iphone they have pretty good documentation (you can use the search bar there) on all the classes and have a lot of good sample code..
I really would emphasize the "Related sample code" section on many, if not most, of the documented classes.
But, IMHO, there isn't any easy way of acquiring the knowledge to develop in Cocoa/Cocoa Touch. The API's are so numerous that it simply takes a lot of time and experience. You just have to work on it, look at a lot of books and study the sample source code where available.
I've tried to take a purposeful approach by carving out some time every week to learning a new API/class irrespective of whether my current project needs it or not.
Alternatively, search Joe Hewitt. He's the developer for iPhone facebook. He has a project you can download that demonstrates all the features of facebook. It's an awesome open source project!
When you look something up in Xcode Developer Documentation, you sometimes get a Related Sample Code: text that tells you what Sample the method or property is used in. Too bad you can't click on it to see the code, but if you do click it takes you to the page to download the sample. – mahboudz 0 secs ago
Apple Developer site has all kinds of code examples. Try searching google for a UICatalog project, it will show you all the basic UI stuff you can do, like adding buttons and progressbars through using only code.