Archive for the “Programing” Category

Wednesday, December 1, 2010 Categorized under iPad, iPhone, News Wall, Programing, RSS, Updates, Web

News Wall 2.0 on the way

Major update 2.0 of News Wall for iPhone and iPad has been submitted to Apple’s review team. Even though it is the first update of the app it deserves being a major update. Here are the most important changes:

  • new article style combining images and text
  • advanced article reading view with next/previous buttons
  • completely rewritten feed fetching core
  • really fast feed loading
  • improved feed reading so nearly every feed can be used
  • search feeds by keywords

News Wall Free now runs both on the iPhone and the iPad. It displays ads and has some limitations when it comes to social sharing.

The update will hit the App Store during the next day. Feel free to contact me (you can do this directly in the app now).

Friday, June 25, 2010 Categorized under Programing

How to add notification sounds to your iOS app

Whenever your app finishes work it should notify the user. Adding a short notification sound is one of the simplest things you can do.

First, you need to get a nice sound sample. There are some websites providing clicks and dings and dongs and swuuushes. I love www.oringz.com because the sounds are great and free (it’s always nice to tell author what you gonna do with his work). Place the mp3 file somewhere in your project so it will get in your bundle.

Now to the coding part. Add another framework called “AVFoundation” to your project. It includes the class we will use. Now you need to decide where you want to invoke the playback. I mostly take the main view controller where I import the AVFoundation headers:

#import <AVFoundation/AVFoundation.h>

An instance variable holds the sounds so we do not need to re-create it every time we want to play it:

AVAudioPlayer *newMessageAudioPlayer;

To actually play the sound, we need a little method doing the dirty work:

-(void)playNewMessagesNotification {
	if (newMessageAudioPlayer == nil) {
		NSURL *audioFile = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"notification1" ofType:@"caf"]];
		newMessageAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioFile error:NULL];
	}
	[newMessageAudioPlayer play];
}

The dirty work done here isn’t dirty at all. It checks if the audio player does exist and of not it creates it by passing a NSURL holding the mp3 filename from the bundle. After creating (or not creating) the player itself it simply starts the playback.

Finally we need to clean up. There are two things to consider. Of course, the instance variable needs to be releases when the class itself gets deallocated. And you should be aware of the memory the sound occupies when hanging around as instance variable. Lucky us, we can easily release the sound in cases of low memory since the play method re-creates it if necessary. So add this to the view controllers didReceiveMemoryWarning method:

[newMessageAudioPlayer release];
newMessageAudioPlayer = nil;
Friday, May 28, 2010 Categorized under iPad, Paper Pile, Programing

A word on text shortening

Some users complain about the fact that Paper Pile shortens article texts so they need to open the web view to read the full version.

Firstly, they’re right. It is annoying having to tap, count to 3, tap on “Open…”, wait until the website has loaded.
That’s why the next update introduces a full text view activated just by tapping on the article. You than will have the choice to load the website.

Secondly, there is, somehow, no way other than cut the stories short if necessary. A newspaper’s layout highly depends on filled areas. It just does not look like a newspaper if there are to many emtpy spaces hanging around. To proof my word, I’ll show you a screenshot of the full text articles when using a very famous feed. Most feeds publish their news this way.

Feel free to suggest different way about dealing with these things. I appreciate every single hint.

Friday, May 28, 2010 Categorized under iPad, Paper Pile, Programing, Updates

Review at padvance.com – Bug fixes

Grant Holzhauser wrote a review about Paper Pile at padvance.com. It’s does not rate the app very good, I grant, but Grant mentions a bad bug that makes article texts get rendered strange. I focused on this and fixed it. Now the good news, you do not need to update the app.

To enjoy the new handling you simply need to refresh your pages. If the pages do not get re-created (because there are no new articles) please restart the app.

Wednesday, April 28, 2010 Categorized under Programing

How to make FMDB “thread-safe”

Using SQLite in your iPhone project means dealing with pure C functions. Fortunately, there are helpful tools wrapping these function in Objective-C objects. FMDB is easy to use and open source so that it could be a perfect solution.

Since Paper Pile starts multiple threads to load new articles and render the newspaper’ pages, database queries may happen at the same time. The FMDB classes pay attention to the fact that only one operation on the database is allowed by “locking” the database.

Every method that forwards the action to SQLite C-functions sets the instance variable inUse to YES after checking that it is NOT YES. After finishing the work the variable gets set back to NO. This way, every instance of FMDatabase can only perform one action. Assuming most apps use a singleton FMDatabase instance, one thread cannot execute SQL statements while another threads is already doing so. By implementation, the second thread’s statement is simply ignored.

There is no easy way to enable real concurrent statement execution. However, we can change the conflict behavior to a way that that every statement gets at least executed.

Simply replace the three occurrences of this code

if (inUse) {
    [self compainAboutInUse];
    return NO;
}

with this code

while (inUse) {
    usleep(50);
}

Now the execution will be paused until the other thread will have finished it execution while the check is performed every 50 milliseconds. Of course, the order of execution is not predictable anymore. However, when using multiple threads dependencies should be handled within the threads anyway.