Focus on Apple Watch – App: Mini Stats

This simple app helps you to keep your iPhone more often in jacket, purse or pocket.
The functionality of MiniStats is very simple: it is an info screen with different data from your iPhone. So you can check directly on your wrist how full the battery of your iPhone is, how much free space is still available and to what WiFi or 3G / 4G network you are connected.
Below the name of the WiFi and 3G network you can also see the available upload and download speed.

MiniStats becomes very handy if your iPhone is in another room and you want to check the battery, or that you are indeed connected to a WiFi network. This information is also available on its iPhone app, but with all data available on your wrist, there is no need to get it out of your pocket.

For €0,99 MiniStats by Tobias Wiedenmann is a no-brainer, so go and get it.

Using Objective-C in Swift projects with a bridging-header

A general problem with starting a new project in a new language is that most of the times you are missing the libraries, classes etc. you feel comfortable with.

Same happens with making the switch from Objective-C to Swift.

But there is a solution that is called “bridging header”, that brings Objective-C into Swift.

Using it , its not that complicated.

  1. create a .h file in your project, e.g. projectname-bridging-header.h
  2. open the Build Settings in your project targets and search for “bridging
  3. add your filename (here: projectname-bridging-header.h) to the “Objective-C Bridging Header” including the path the file can be found (e.g. projectname/projectname-bridging-header.h)
  4. open your projectname-bridging-header.h and add your import lines as you would do in a normal Objective-C header (e.g. #import “foo.h”)

That’s it.

Now you can access and use the new available classes in the Swift way.

Fix timezone settings for “Strict Standards: strtotime()” error in CakePHP

When i installed CakePHP on a hostet webspace (e.g. 1und1) i received this error message:

Strict Standards: strtotime(): It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘Europe/Berlin’ for ‘CEST/2.0/DST’ instead in /lib/Cake/Cache/CacheEngine.php on line 60

It seems that there are at least 2 solutions for that issue:

  1. adding this line of code into app/Config/core.php

    This one worked fine for me.

  2. adding/changing this line in your php.ini
    date.timezone = Europe/Berlin

    This did not work for me, but therefore this seems to be a solution for other users, i thought i should put it in here, too.

Simplify an array of numbers to a string of numbers with ranges

The task i had was to simplify an array with a large list of numbers to a numberlist with ranges that is is shown with hyphens.

This is an example of numbers in an array:
and this is how the result should look like:
1, 3, 7, 12-14, 17, 22-27, 30, 38-42, 55

I thought this function might be pretty useful for others, so check it out.
The function expects an array of numbers, sorts the given numbers and will return a string of numbers.

function compressNumberList(numArray) {
	var str = '';
        numArray.sort(function(a,b){return a-b});
	for(var i = 0; i < numArray.length; i++) {
		var tmp;
		var hyphen = &#039;-&#039;;
		tmp = numArray[i];
		var rest = numArray.length - i;
		var count = 0;
		for(var j = 1; j < rest; j++) {
			if(tmp+j == numArray[i+j]) {
				count = j;
		var comma = &#039;, &#039;;
		if(numArray.length == i+1) {
			comma =&#039;&#039;;
		if(count > 0) {
			i = i +(count-1);
			comma = hyphen;
		str += tmp + comma;
	return str;

Of course, it's not very complicated, but i am sure it might save you some time 😉
Comments with a “translation” into other languages (e.g. python, c++, etc.) would be very welcome and helpful for others. 😉


Dynamic height for UILabel to fit to content length

Starting with objective-c for iOS is a big step, when you come from the always dynamic “web”-world with HTML and CSS. Just put content in some HTML Tag and it normally grows with the length of it.

With objective-c and iOS a lot things are just different, like the elements you can choose to put content in, or the way navigation works.
One common problem – especially for beginners – is to accept that you have to calculate sizes for elements programmatically, e.g. UILabel.
When we use the interface builder, there are controls for that, but this is all static so far, e.g. “Lines”.

So how can i resize the UILabel if i do not know the content length?
It is not as complicated as it seems in the first place.

Bildschirmfoto 2013-05-01 um 11.16.47

If you use the Interface Builder and put a UILabel in your layout it is important to set “Lines” to 0. i often forgot this, so i think its guess is a common mistake, this is why i point it out 😉

Now we fill the UILabel (here: publicTransport) with a value from a NSDictionary and resize it to the necessary size.

publicTransport.text = [addresslist valueForKey:@"public"];
NSString *message = [addresslist valueForKey:@"public"]; 
CGSize maximumLabelSize = CGSizeMake(280,1000);

// use font information from the UILabel to calculate the size
CGSize expectedLabelSize = [message sizeWithFont:publicTransport.font constrainedToSize:maximumLabelSize lineBreakMode:NSLineBreakByWordWrapping];

// create a frame that is filled with the UILabel frame data
CGRect newFrame = publicTransport.frame;

// resizing the frame to calculated size
newFrame.size.height = expectedLabelSize.height;

// put calculated frame into UILabel frame
publicTransport.frame = newFrame;

Just copy this code and paste it into your project. Replace the label name publicTransport with the label name you need to resize and this should all work fine 😉


Simple webservice authentication using cakephp. A closer look.

After bringing up a very simple way to get authentification done in an older post, it is time to give it a closer look and bring up some code that will help to get things done.

I use one single controller to handle all external requests the webservice could receive, i do not know if that is “best practice”, but it seems reasonable
to me at this point. All responses are JSON, so i simply named the controller “json_controller“… 😉

Of course the user must log in first. For that he makes a request on “/json/login“.
The process is pretty much standard, the user logs in with his credentials as in the normal web application.
For this (my first) approach it was important to make it work before i start with (at this point) unnecessary security stuff.

public function login () {
	if($this->request->is('post')) {
		$post['username'] = $this->request->data['username'];
		$post['password'] = $this->request->data['password'];
		$post['android_registration_id'] = $this->request->data['reg_id'];
		$data['hash'] = $this->Auth->password($post['password']);
		$check = $this->User->find('first',
				'conditions' => array(
					'username' => $post['username'],
					'password' => $data['hash']
		$save = array();
		$return = array();
		if($check) {
			$save['id'] = $check['User']['id'];
			$save['token'] = $this->Auth->password($post['username'].date('dmY'));
			$save['android_registration_id'] = $this->request->data['reg_id'];
			$save['last_mobile_login'] = date('Y-m-d H:i:s');
			if($this->User->save($save)) {
				$return['return']['token'] = $save['token'];
				$return['return']['hash'] = $data['hash'];
				$return['return']['id'] = $check['User']['id'];
				$return['return']['username'] = $check['User']['username'];
			} else {
				$return = false;
		} else {
			$return = false;
	return new CakeResponse(array('body' => json_encode($return, JSON_NUMERIC_CHECK)));

The credentials will be checked against the request and the necessary data will be given back to the request source. As you can see i am saving the additional information (android_registration_id) already, so extending the code will be done quickly.
The returned JSON object will contain the token and the hash that will be needed for any further requests on the webservice and needs to be saved in the app on the device.
Continue reading “Simple webservice authentication using cakephp. A closer look.” »

Create dynamic height for UITableViewCells in iOS

During my try creating a forum view with threads and posts for ios devices i figured out that there is no option to get an automatic height for table cells if the content is larger then the layout i created in the .xib file.

After not finding a proper and easy solution in several developer forum, it took me some days to figure out a way to get it done in a way that seems to work for me.
Calculating the size of the content seems to do the trick.

In my layout i have label for the username, a label for the date of the post and the message itself.
The message label is the only content, that could cause any issues, so this is the only part that needs to be calculated.

Here is the code that does it for me:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSObject *Thread = [_postArray objectAtIndex:indexPath.row];
    NSString *message =[Thread valueForKeyPath:@"Forum.message"];
    CGSize maximumLabelSize = CGSizeMake(296,9999);
    UIFont *font = [UIFont systemFontOfSize:17];
    CGSize expectedLabelSize = [message sizeWithFont:font constrainedToSize:maximumLabelSize lineBreakMode:NSLineBreakByWordWrapping];
    int a = expectedLabelSize.height + 55;
    return a;

– you can get systemFontSize also through a function, so it could be dynamic
– 55 is the fix height of the content above the message label

If there are other – maybe better or more comfortable – ways, please let me know. 🙂

Using Doxygen in Xcode

This is just a quick recommendation to a blog post from my friend Oliver, writing about how to implement Doxygen in Xcode and automate it.

If you develop your software in groups, create a framework, or just want to show your latest development project to other people, your want documentation for your code. For Objective-C in Xcode projects there are solutions like HeaderDoc or AutoDoc, but the lack of solid documentation seems almost ironic. So I found doxygen, which has better documentation and supports multiple platforms, multiple programming languages, and multiple output formats.

Read the very helpful post at

Create a simple authentication used by a smartphone app with a cakephp webservice

Everybody is using smartphones to get there information on the go. To provide the necessary information there a several ways to do so, e.g.:

  • your usual web page
  • your usual web page with a special mobile layout
  • a native smartphone app retrieving its information via a provided web service.

In this post i take a closer look at the last point in a very simple way, which gives you an idea of how things can work and you can play around with.

For this simple approach the smartphone app needs to be able to store data on the device.

This is how the entire process works in my case:
The already registered User logs in via his smartphone app, which will send the username and password via post request to an url.

All the authentification happens on the website, so there will be no encryption done on the mobile device, which means there is no extra work to be done, when some thing on the webservice needs to be changed.

if username and password are correct the website will generate a token, saves it and send a response with either false or an array with the token and the encrypted password (i used the already encrypted password from database) that needs to be saved in the app.
From now on, the web service expects those values on every request and authenticates this device and therefor the user.

As long as this token is sent the app will be authenticated and on every login the token will be renwed for this user, which means that a login from another device will delete the current token and writes a new one that will be different. That means, that only one device can be logged in at the same time.

Continue reading “Create a simple authentication used by a smartphone app with a cakephp webservice” »

Java on Mac OS X Mountain Lion

Like the most people recognized Mac OS X Mountain Lion does some weird stuff to already installed software. So does it to Java and gives us a message that tells us to download some version from their website (which is not installable) or from some Oracle site.

The quicker and easier way is to use the already installed version of Java and let it update itself pretty quick.
All you have to do is:

  • open the hotspot search (cmd + space)
  • enter “java”
  • select the “java preferences” icon

Thats it.

Now it is downloading the newest Java version and installs it.

I hope this will work for you too.

Link: Download Java 7 here