Get to the point: Detect Internet Connection
Feb 21st
We will be using Apple’s reachability class to detect the state of the Internet connection. Reachability is freely available from Apple’s website: http://developer.apple.com/iphone/library/samplecode/Reachability/
1- Create a View-based Application and name it InternetConnectionState
2- Download Apple’s Reachability App source code and copy reachability.h & reachability.m files to your application’s Classes folder.
3- Add these files to your XCode project. Right click the Classes folder and select Add->Existing Files (see Figure 1). Select the reachability.h & reachability.m files and add them to your XCode project. You should see these file under the Classes folder (see Figure 2).
Figure 1
Figure 2
4- Add the “SystemConfiguration” framework. Right click the Frameworks folder and select Add->Existing Frameworks. Select & Add the SystemConfiguration.framework (see Figure 3).
Figure 3
5- Open the InternetConnectionStateAppDelegate.h and add the following code below the #import <UIKit/UIkit.h> line:
@class Reachability;
Add the following lines inside @interface:
Reachability* hostReach;
Reachability* internetReach;
Reachability* wifiReach;
Finally, add these lines above the @end line:
- (void) updateInterfaceWithReachability: (Reachability*) curReach;
- (void) statusView: (NSString*) statusString;
6- Open the InternetConnectionStateAppDelegate.m and add this line below the last #import:
#import "Reachability.h"
7- Add the following lines of code to the applicationDidFinishLaunching function:
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reachabilityChanged:) name: kReachabilityChangedNotification object: nil];
hostReach = [[Reachability reachabilityWithHostName: @"www.google.com"] retain];
[hostReach startNotifer];
[self updateInterfaceWithReachability: hostReach];
internetReach = [[Reachability reachabilityForInternetConnection] retain];
[internetReach startNotifer];
[self updateInterfaceWithReachability: internetReach];
wifiReach = [[Reachability reachabilityForLocalWiFi] retain];
[wifiReach startNotifer];
[self updateInterfaceWithReachability: wifiReach];
8- Copy these functions below the applicationDidFinishLaunching function:
- (void) networkStatusChanged: (Reachability*) curReach
{
NetworkStatus netStatus = [curReach currentReachabilityStatus];
BOOL connectionRequired= [curReach connectionRequired];
NSString* statusString= @"";
switch (netStatus)
{
case NotReachable:
{
statusString = @"Access Not Available";
connectionRequired= NO;
[self statusView:statusString];
break;
}
case ReachableViaWWAN:
{
statusString = @"Reachable WWAN";
[self statusView:statusString];
break;
}
case ReachableViaWiFi:
{
statusString= @"Reachable WiFi";
[self statusView:statusString];
break;
}
}
if(connectionRequired)
{
statusString= [NSString stringWithFormat: @"%@, Connection Required", statusString];
}
}
- (void) statusView: (NSString *) statusString{
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, 320, 50)];
titleLabel.font = [UIFont systemFontOfSize:15];
titleLabel.textColor = [UIColor blackColor];
titleLabel.backgroundColor = [UIColor whiteColor];
titleLabel.opaque = YES;
titleLabel.textAlignment = UITextAlignmentCenter;
titleLabel.text = statusString;
[viewController.view addSubview: titleLabel];
}
- (void) updateInterfaceWithReachability: (Reachability*) curReach
{
if(curReach == hostReach)
{
BOOL connectionRequired= [curReach connectionRequired];
NSString* baseLabel= @"";
if(connectionRequired)
{
baseLabel= @"Cellular data network is available.\n Internet traffic will be routed through it after a connection is established.";
}
else
{
baseLabel= @"Cellular data network is active.\n Internet traffic will be routed through it.";
}
}
if(curReach == internetReach)
{
[self networkStatusChanged: curReach];
}
if(curReach == wifiReach)
{
[self networkStatusChanged: curReach];
}
}
- (void) reachabilityChanged: (NSNotification* )note
{
Reachability* curReach = [note object];
NSParameterAssert([curReach isKindOfClass: [Reachability class]]);
[self updateInterfaceWithReachability: curReach];
}
9- Save & Build your application. If there were no errors you should get something similar to Figure 4.
Figure 4
Get to the point – Code Snippets: Dialing a number, sending SMS & Email from within your app
Feb 8th
These code snippets will allow you to dial a number, send an SMS & send an e-mail from within your application. They will all open up the selected application and close yours.
Dialing a number
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://123456"]];
Sending an SMS
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms:123456"]];
Sending an E-mail
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto:amasso@amasso.info?subject=Hello&body=Testing your code snippet."]];
Get to the point – Code Snippets: NSString to NSInteger & vice versa
Feb 7th
NSString to NSInteger code snippet:
NSString *strTest = [NSString stringWithFormat:@"%d", 10];
NSInteger to NSString code snippet:
NSInteger iTest = [strTest integerValue];
clouding.me beta launched!
Aug 26th
The beta version of www.clouding.me is online. Register to beta test this new clouding service. I will soon add an iPhone web version. The iPhone app version is on its way, hopefully Apple will approve it.

Follow me on Twitter
Dynamic username as subdomain system with .htaccess
Feb 8th
Create an .htaccess file with the following code to build a dynamic username as subdomain.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.mydomain\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?username=%1 [L]
All visits to http://username.mydomain.com will redirect to index.php?username=subdomain. You can then assign that username to a cookie and build the user’s web page.
Follow me on Twitter




























