DEPRECIATED use KMWordPress instead.
DEPRECIATED use CBPWordPress instead.
TTWordPress is a library I wrote to easily display a WordPress blog in an iOS app. I originally wrote it for the Visionary.ie app and was then able to expand on that to create the Broadsheet.ie app. Since I found it useful, I thought I’d release it into the wild and see what happens.
To provide the data from a WordPress blog is a nice machine readable format, the excellent JSON API plugin is used. Obviously, it needs to be installed for the iOS to be able to retrieve anything but that’s a trivial matter. If you want users to be able to comment on posts, you need to activate the ‘Respond’ controller in the API settings. On the iOS side of things, the library uses Three20 for the consuming the JSON and displaying the information in tables.
To use the library in your own app, you first need to add Three20 to your project (if you’re not already using it). Open the example TTWordPress project and copy the WordPress folder and all its contents to your project.
To point the library at your own blog, you need to edit the following line in TTWordPress.h:
#define WP_BASE_URL @"http://ttwordpress.karlmonaghan.com/"
In this file, you can also change the default title for the latest posts view and the way dates are displayed for posts and comments.
Then in your AppDelegate, add the following includes:
#import "WordPressBlogViewController.h" #import "WordPressAddCommentViewController.h"
Then add the following lines:
[map from:@"tt://examplepostlist" toSharedViewController:[WordPressBlogViewController class]]; [map from:@"tt://blog/author/(initWithAuthorId:)" toViewController:[WordPressBlogViewController class]]; [map from:@"tt://blog/category/(initWithCategoryId:)" toViewController:[WordPressBlogViewController class]]; [map from:@"tt://blog/post/comment/(initWithPostId:)" toModalViewController:[WordPressAddCommentViewController class]];
The first line sets the path to a view controller that will list the latest posts from your blog, the second shows the posts belong to a particular author, the third from a particular category and the fourth is the modal pop up for making a comment. The assumption here is that the list of posts from your blog will be a tab in your app hence being a shared view controller as opposed to the other two which are created and destroyed on demand.
The final step is to call the latest post view controller from somewhere. In the sample project, it’s added to the UITabViewController. Once you’ve done that, compile and run your app and you should see your blog posts.
The code is available via a Git repo at https://github.com/kmonaghan/TTWordPress.
If you do use it, I’d love to hear from you.
The icon used is from the excellent Glyphish set.
DEPRECIATED use KMWordPress instead.
hi, thanks a lot for your coding. It’s very useful for me. Anyway, I want to ask that is it possible for the code runing on xcode 4.2? Thanks!
It does compile and work under 4.2. are you hitting a problem?
I am very new to xcode. I am afraid I am making some silly mistakes. I download the code in zip format, create a new project, add Three20 framework to my project and copy all files in TTWordpress folder to my project folder. After adding the code above to AppDelegate.m, there are quite a lot errors.
Would you please have any suggestion? Thanks a lot.
Could you paste some of the errors you’re getting?
I have a question. I have used JSON API plugin to pull in posts, pages, articles, things of that nature — but in terms of handling logging in, creating accounts, allowing users to make posts you mention you have to use the respond controller.
Does the code you cite in your post handle all passwords, user names securely, or at the very least encrypt them?
Is using the respond controller the only thing you need to do to handle all the WordPress authorization and comment creation you listed in your article; or do you have to program this stuff in?
Please cite examples where possible in your answer.
The respond controller certainly handles allowing users to comment but I’ve never used it for creating/managing accounts. It’s set up to act the same as the comments on this blog – i.e. take an email address name and optional website along with the comment. there’s no passwords involved so no need to encrypt them.
You’d have to dig into the API to see if it can handle registration of users with password.
The “Add the following lines” code, where do I need to insert that code? In AppDelegate.h ? – If I do that, it gives quite lot of errors, undeclared use of map etc.
Am I doing it wrong? Please help.
Sjors
Yes in the app delegate. Are you properly including the Three20 library?
Hi Karl,
I experience the same issue as Sjors above. There are 2 errors when I add any of the “[map from” lines.
The first is a parse issue: Expected identifer or “(”
The second is a semantic issue: Use of undeclared identifier “map”
Have you seen or heard of people experiencing these issues before? I’m fairly sure that I added the three20 project correctly and the project builds before adding any of the [map from lines.
If you have any suggestions that would be great thanks.
Hi Kieran,
At a guess the root problem is with your first parse issue. What exactly is the line throwing it?
Hi Karl,
Thanks for getting back so quickly. The errors appear whenever I try to add any of the map from lines. The one I am trying to sort out at the moment is..
“[map from:@”tt://examplepostlist” FirstViewController:[WordPressBlogViewController class]];”
You are correct that the parse issue seems to be where the problem lies. Xcode seems to have a problem with the square brackets and when I try to use “(” type brackets instead it removes the semantic error but still leaves a parse error with the brackets.
Sorry that should have been toSharedViewController instead of FirstViewController
Have a look at:
https://github.com/kmonaghan/TTWordPress/blob/master/TTWordpress/TTWordpressAppDelegate.m
Make sure you’ve lines 15 to 19 in your app delegate.
I tried to intall and use it (Mac OS Lion, XCode 4.5), but received tons of warnings and erros when building. Isn’t there an working example we could download to test it?
Did you install three20? What sort of errors are you getting?
Ok, I was able to solve many issues. Lots of files downloaded from the git repository we’re treated as “not there” by XCode, but I could manually insert them. Now, I’m getting “parse issues” when inserting the [map from…] codes. If i just comment them, I get “Apple Mach-O Linker Error”:
Undefined symbols for architecture i386:
“_OBJC_CLASS_$_WordPressImageViewController”, referenced from:
objc-class-ref in WordPressPostViewController.o
“_OBJC_CLASS_$_WordPressModel”, referenced from:
_OBJC_CLASS_$_WordPressPostModel in WordPressPostModel.o
“_OBJC_CLASS_$_WordPressPostsModel”, referenced from:
objc-class-ref in WordPressDataSource.o
“_OBJC_METACLASS_$_WordPressModel”, referenced from:
_OBJC_METACLASS_$_WordPressPostModel in WordPressPostModel.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Sorry for troubling you. I just got it. The answer was in my question: the files I added manually wasn’t with the “target mempership”.
Sorry for all the trouble, I’m just beginning with iOS. It’s now working and I’ll spread the word: this library is awesome!
Hi,
I’m also quite new to Xcode and I’m having trouble understanding how to copy the files into my own project. Is this something I’m supposed to do directly from the finder or in Xcode? Can you detail a bit that process?
Thanks a lot,
C/
If you right-click in the file browser you should see “Add files to ‘‘”. Select that and you’ll be able to browse to the file. You can also drag and drop from a finder window.