Marko Heijnen discussed creating native mobile apps with WordPress. He explained that mobile is growing and developers may want to create native apps. The API currently uses XML-RPC but JSON is an alternative. Developers need to communicate with mobile developers to build an API and additional fields. Methods like getRecentPosts retrieve post data. Plugins like JSON API can be used to support JSON. Developers should return minimal data and cache responses. Special post types and admin pages can manage mobile content and push notifications. WordPress is flexible and can power mobile apps.
3. History
2006: Started with WordPress
2009: Started with iOS development
2010: First patch to WordPress ( 3.0 )
2011: Combined iOS development with WordPress
2012: First WordCamp presentation
8. Native vs mobile
Build a native app when:
People are going to use it quite often ( daily basis )
Features that aren’t possible for web ( yet )
A lot of users request for it ( 10.000 > )
Customers really want an app
10. What does it mean for you
You need to communicate with another developer
Need to build an API that the developer can use
So you need to understand what a mobile developer wants
Need to build additional fields in WordPress for information
that the mobile app can use
21. Response
<?xml version="1.0"?>
<methodResponse>
<params>
<param>
<value>
<array><data>
<value><struct>
<member><name>dateCreated</name><value><dateTime.iso8601>20110904T18:15:26</dateTime.iso8601></value></member>
<member><name>userid</name><value><string>1</string></value></member>
<member><name>postid</name><value><string>1</string></value></member>
<member><name>description</name><value><string>Welcome to <a href="http://network.nginx.markoheijnen.com/">WordPress Network Sites</a>. This is your first post. Edit or delete it, then start blogging!</
string></value></member>
<member><name>title</name><value><string>Hello world!</string></value></member>
<member><name>link</name><value><string>http://test.network.nginx.markoheijnen.com/2011/09/04/hello-world/</string></value></member>
<member><name>permaLink</name><value><string>http://test.network.nginx.markoheijnen.com/2011/09/04/hello-world/</string></value></member>
<member><name>categories</name><value><array><data>
<value><string>Uncategorized</string></value>
</data></array></value></member>
<member><name>mt_excerpt</name><value><string></string></value></member>
<member><name>mt_text_more</name><value><string></string></value></member>
<member><name>mt_allow_comments</name><value><int>1</int></value></member>
<member><name>mt_allow_pings</name><value><int>1</int></value></member>
<member><name>mt_keywords</name><value><string></string></value></member>
<member><name>wp_slug</name><value><string>hello-world</string></value></member>
<member><name>wp_password</name><value><string></string></value></member>
<member><name>wp_author_id</name><value><string>1</string></value></member>
<member><name>wp_author_display_name</name><value><string>marko</string></value></member>
<member><name>date_created_gmt</name><value><dateTime.iso8601>20110904T18:15:26</dateTime.iso8601></value></member>
<member><name>post_status</name><value><string>publish</string></value></member>
<member><name>custom_fields</name><value><array><data>
</data></array></value></member>
<member><name>wp_post_format</name><value><string>standard</string></value></member>
</struct></value>
</data></array>
</value>
</param>
</params>
</methodResponse>
22. XML-RPC
Critics of XML-RPC argue that RPC calls can be made with
plain XML
XML-RPC uses about 4 times the number of bytes compared
to plain XML
Need a lot of code on the app side
In the end the size of requests/responses do mather
23. Is this the best way or
are there alternatives?
25. What is JSON
JavaScript Object Notation
Use JSON as alternative to XML
It is derived from the JavaScript scripting language
Lightweight text-based open standard
26. Why JSON
Lighter and faster than XML
JSON objects are typed
Array, object, string, number, boolean and null
Great libraries for mobile platforms
iOS 5 does have native support for JSON
Easy to parse on mobile platforms
29. Plugins you can use
JSON RPC - http://wordpress.org/extend/plugins/wp-json-
rpc-api/
JSON API - http://wordpress.org/extend/plugins/json-api/
WP RESTful - http://wordpress.org/extend/plugins/wp-
restful/
Be aware that these plugins aren’t up to date
31. JSON API
Great to use because of the use of hooks
Good information on the plugin page
Simple backend interface
I use a modified version of it
Added consumer key/secret
33. How to implement
function add_hello_controller( $controllers ) {
$controllers[] = 'hello';
return $controllers;
}
add_filter( 'json_api_controllers', 'add_hello_controller' );
function set_hello_controller_path() {
return "/path/to/theme/hello.php";
}
add_filter( 'json_api_hello_controller_path', 'set_hello_controller_path' );
34. How to implement
<?php
class JSON_API_Hello_Controller {
public function hello_world() {
return array( "message" => "Hello, world" );
}
}
?>
35. Important to know
Only return data that is needed
Return as less HTML as possible
Don’t change the feed without notifying the app developer
A call shouldn’t take to long, speed is everything
Cache the data if possible
Transients: http://codex.wordpress.org/Transients_API
38. Post types
Add separate meta box for mobile content
Even the ability to overrule the title
Additional user capability, so not everyone can manage it
Maybe even create a special post type for mobile content
39. Special admin page
Only for mobile configuration
Store settings
Store default pages for mobile like privacy disclaimer
40. Push notifications
Create ability to send push notifications in a smart way
Add to posttype
Make a separate box on dashboard or admin page
You can handle the sending yourself
Or use for example the services of Urban Airship
41. Last word
WordPress is a CMS
Can be used in a lot of ways
Sometimes look further then the plugin section