I’ve had a request from my client to convert their WordPress website into an App for Android and iPhone. I’ve looked around at a number of options and it seems doable especially for just the blog section as it’s the rss that can be used as the db but I’m using the WP site as a customer and want to know if it’s possible to pull all of the site’s content out to save as RSS and use as the DB please.
Or any better approaches would be appreciated?
Many thanks
Here is a list of points that will help you in order to make an iOS app for your WordPress blog:
You can either parse XML in the RSS feed, JSON by installing a JSON plugin in your WordPress or you can also parse HTML directly.
1) I would suggest using NSXMLParser and parse the RSS feed instead of using JSON. Reason being, if something goes wrong to the JSON plugin, or the developer just stops updating the plugin that you are using or the plugin crashes etc. the JSON data will be crashed and so does the data in the native app that you have made using the JSON plugin. On the other hand, RSS and XML data remains there even you blog crashes. This will not disturb the app users. Same goes with parsing HTML, i won’t recommend it because if you change your theme and the structure of the HTML changes, the parse data in the iOS app will be effected and you will have to do the whole work again and then wait for the App Store submission. So lets stick to parsing XML in the RSS feed.
2) Parse the RSS feed using NSXMLParser. You can also use third party libraries available that parses the XML feeds but i would suggest to stick with the built in NSXMLParser as there is plenty of help available online for it.
2) To connect to the web services like XML feed, you can use third party libraries like AFNetworking or you can use Apple’s built in libraries like NSURLConnection and other classes to connect and download the data from the webservice.
5) Here are some very easy tutorials for the steps above. How to Use NSURLConnection, How To Parse RSS with NSXmlParser
6) After that one of the most important thing is to download images asynchronously in the UITableViewCells where you are displaying your blog posts. I would suggest you to use SDWebImage library as it will save you a lot of time as its a project in its own and you cannot waste your time building something thats already there.
7) Then you have to create a UIWebView and when the row of any blog post inside the UITableView is tapped, you can use the link to segue in the UIWebView to show the actual blog post. You can use didSelectRowAtIndexPath in order to pass data between view controllers.
8) Below the view controller that contains the UIWebView, you can add functions like stop, refresh, sharing on Facebook and Twitter etc.
9) As you can see that is a lot of work and business people just think that its easy to develop an iOS app but the truth is that it takes some time to completely package the app and submit to the App Store. You can also outsource your project by using service like Convert WordPress Blog To iOS App that is completely for free if you share revenue with them but its your choice and i recommend you to code it yourself to have complete ownership of you app.
Rest is just a matter of choice of different functions you would like to make in your app to stand out from the rest. You can add a Facebook style sliding navigation controller on the left side to create and parse specific categories on your blog, you can use Flipboard style swiping in your Web View etc etc. For that stuff there are a lot of third party libraries available.
Hope this helps!
Check out JSON API plugin. It will allow you to have a RESTful API for most of the content on your website.
If you don’t want to have an API in WordPress (i.e. you want it on a different domain/subdomain, have separate codebase etc.), you could do the same through pure PHP, or using a microframework, such as Slim.
In this approach you would load WordPress through requiring
/wp-load.php
. All functions would become available to you (such asget_posts()
) and you would still be able to query the database the same way as if you were writing a WP plugin:global $wpdb;
$results = $wpdb->query(“your query here”);
Notes
There are a couple of tips to get better performance using the second approach:
Skip loading theme engine as you probably won’t need it if you serve everything in JSON:
define(‘WP_USE_THEMES’, FALSE);
Prevent executing WP cron on any of the API calls. This will make sure there will be no hangs in the API calls because the cron is being executed in the background.
define(‘DISABLE_WP_CRON’, TRUE);
It’s been 4 years since the question was posted, so the accepted answer is not that relevant anymore. WooCommerce launched the WooCommerce REST API that comes with all WordPress installations by default. So there’s no need for any extra endpoints or additional plugins. Just use the REST API directly from your mobile app.
A solution may be to use something like json-API plugin to provide a simple API to your contents.
You can also use this wordpress plugin: https://wordpress.org/plugins/androapp/
this indeed usage JSON API Plugin as suggested by TopSiteMaker earlier.
It also has in-built support for monetization, push notifications, image sharing in built. It currently provides android app only though, do give it a try