iOS 9 Error: The resource could not be loaded because the App Transport Security policy requires the use of a secure connection

With the release of iOS 9 this week, there’s some changes to the development of the application.

If you are writing an app now and it calls certain external api or webservices, you will hit the following error.

The resources could not be loaded because the App Transport Security policy requires the use of a secure connection.

There are 2 solutions to this, first make sure that the connection you are trying to make support https. Change that in your codes and build, if error persist.

The second solution is to add a new value to the Info.plist in your solution file.

Add a Key called NSAppTransportSecurity as a Dictionary

Add a sub-key called NSAllowsArbitraryLoads as Boolean
and set its value to YES.

Adding Google Analytics to your wordpress

So last night I decided to add the Google Analytics to my blog and see what the most rewarding post/s.

1. Visit www.google.com/analytics to sign up with your Google Account.

2. You need to accept some T&A before continuing the process.

3. Add a new Website, enter your domain name.

4. Now, Google will generate a tracking code for you to input into your webpage.

Something like this,

<script>
(function(i,s,o,g,r,a,m){i[‘GoogleAnalyticsObject’]=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,’script’,’//www.google-analytics.com/analytics.js’,’ga’);

ga(‘create’, ‘XXXXXXXXX’, ‘auto’);
ga(‘send’, ‘pageview’);

</script>

 

To insert that into your wordpress blog, use the following plugin, https://wordpress.org/plugins/insert-headers-and-footers/

GoogleAnalytics

Adding a side menu to your IOS App – RESideMenu Storyboard Tutorial Part 2

This is continuation from Part 1.

We have previously created the Storyboard, now we need to configure some settings.

RootViewController.h – Add the following codes

RootViewCodes

#import "RESideMenu.h"

@interface RootViewController : RESideMenu <RESideMenuDelegate

RootViewController.m – Add the following codes

- (void)awakeFromNib
{
    self.menuPreferredStatusBarStyle = UIStatusBarStyleLightContent;
    self.contentViewShadowColor = [UIColor blackColor];
    self.contentViewShadowOffset = CGSizeMake(0, 0);
    self.contentViewShadowOpacity = 0.6;
    self.contentViewShadowRadius = 12;
    self.contentViewShadowEnabled = YES;
    
    self.contentViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"contentViewController"];
    self.leftMenuViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"left"];
    self.backgroundImage = [UIImage imageNamed:@"Stars"];
    self.delegate = self;
}

#pragma mark -
#pragma mark RESideMenu Delegate

- (void)sideMenu:(RESideMenu *)sideMenu willShowMenuViewController:(UIViewController *)menuViewController
{
    NSLog(@"willShowMenuViewController: %@", NSStringFromClass([menuViewController class]));
}

- (void)sideMenu:(RESideMenu *)sideMenu didShowMenuViewController:(UIViewController *)menuViewController
{
    NSLog(@"didShowMenuViewController: %@", NSStringFromClass([menuViewController class]));
}

- (void)sideMenu:(RESideMenu *)sideMenu willHideMenuViewController:(UIViewController *)menuViewController
{
    NSLog(@"willHideMenuViewController: %@", NSStringFromClass([menuViewController class]));
}

- (void)sideMenu:(RESideMenu *)sideMenu didHideMenuViewController:(UIViewController *)menuViewController
{
    NSLog(@"didHideMenuViewController: %@", NSStringFromClass([menuViewController class]));
}

Take note of the leftMenuViewController in the awakeFromNib method. We going to set those identifier to our storyboard’s viewcontroller.

Storyboard – RootViewController

Set the class to RootViewController.

SetClassforRootView

Storyboard – NavigationViewController

Set the StoryboardID to contentViewController.

 

SetNavigationControllerStoryboardID

 

Storyboard – HomeViewController

  1. Set both the Class and Storyboard ID.

SetClassandIDforHomeController

2. Now add a UIBarItem to your navigation.

BarButtonItem

3. Link the UIBarItem with the presentLeftMenuAction.

Linkthemup

 

Now you are good to test! Ping me up if you have issue.

Adding a side menu to your IOS App – RESideMenu Storyboard Tutorial – Part 1

In this tutorial, we are going to cover some of the quick and easy way of adding a side menu to your iOS app.

Basic Housekeeping

Firstly, let me introduce you to http://www.cocoacontrols.com, this is repository that provides a bunch of custom controls that are designed for iOS and Mac OSx. Sometimes we should not reinvent the wheel, but harness the power of the internet and community around.

Next, we are going use cocoa pods, if you are not sure what that is, head over to the following url -> Raywenderlich’s intro to cocoapod

So I have choose, RESideMenu, an amazing and beautiful control. GitHub – RESideMenu.

Getting Started – Adding RESideMenu to your project

  1. Adding the library into your project, if you have a pod file add the following:
    pod 'RESideMenu', '~> 4.0.7'
    
  2. Within your Terminal, browse to your XCode project location and type the following:
    pod install
  3. Xcode should generate a xcworkspace extension for you. Moving forward you should be only using this file.

Getting RESideMenu to work

Let create the following files in your project.

  1. RootViewController – Add New File -> Cocoa Touch Class
  2. HomeController – Add New File -> Cocoa Touch Class

The above should inherit UIViewController.

Next in your Main.Storyboard, add the following:

  1. UIViewController
    Searching for UIViewController
  2. UINavigationController

It should look like below after you are done.

Storyboard

In the next post, I am going to show you what we need to configure.

 

 

Google Adsense : account is different from the one registered

Google Adsense allow you to have some ads on your blog or website and allow you to make some money of those ads.

But its not easy to set it up and many a times the information is lacking.

As I was trying to set it up, I got the following error :

 

The Account is different from the one registered.

 

I am utterly confused with this, i tried all sort of ways to fix this but to no result.

The final straw to resolve this issue are as following:

1. Go to your wordpress plugin page

2. Deactivate the Google Adsense Plugin.

3. Delete the Google Adsense plugin along with all the data.

4. Select Add New Plugin, re add the google Adsense plugin

5. Sign in to Google Adsense Plugin again and wait for it to verify that you are the webmaster.

Finally, we are done!

How to setup cocoapods in your Xcode

1. Create a Podfile in your xcode project root directory. A Podfile is a text blank text file.
2. Next add the libraries into your podfile.
pod ‘RESideMenu’

3. Now go to terminal, browse to the location of your Xcode project, enter the following.
pod install

4. You should have a .xcworkspace extension created, you should use this workspace project moving forward.

Setting Global Value in Objective C

Setting and getting value using a global singleton in objective c is a programming pattern that allow you store in the system memory.

There’s a lot of discussion regarding this design pattern both on the pros and cons, visit the following to read more. http://stackoverflow.com/questions/137975/what-is-so-bad-about-singletons

To Setup the Singleton Object in your Xcode project.

1. Create a class (.h/.m) and name them GlobalSingleton.

2. In the GlobalSingleton.h file, add the following section of codes.

#import <Foundation/Foundation.h>

 

@interface GlobalSingleton : NSObject

 

//This are the property you are going to store in the Singleton object

@property (nonatomic, retain) NSArray *array_SideViewOptions;

 

@property (nonatomic, retain) bool *offline;

 

+(GlobalSingleton*) getValues;

 

@end

 

Notice the Singleton Properties, these are the different type of properties you intend to store inside the object.

3. In the GlobalSingleton.m file, add the following section of the codes.

#import GlobalSingleton.h

static GlobalSingleton* singleton;

static dispatch_once_t pred;

@implementation GlobalSingleton

 

@synthesize offline;

@synthesize array_SideViewOptions;

 

+(GlobalSingleton*) getValues{

    

    dispatch_once(&pred, ^{

        singleton = [[GlobalSingleton alloc] init];

    });

    returnsingleton;

    

}

 

@end

Notice the synthesize portion, thats allow you have to do in future if you add more properties.

 

Using the Singleton – Setting Value.

#import “GlobalSingleton.h”


[GlobalSingleton getValues].array_SideViewOptions = [[NSArray alloc]initWithObjects:@“apple”,@”Spidy”,@”Settings”,@”Feedback”, nil];

Using the Singleton – Getting Value.

#import “GlobalSingleton.h”

array_SectionOne = [GlobalSingleton getValues].array_SideViewOptions;

 

 

Using Reachability to test for Internet Connectivity IOS

Any apps that you build today will require some form of internet connectivity.

Today’s app is getting more and more intuitive and should have the ability to check on the internet connective and prompt the user of the app.

To do that we will be using the following library, Reachability. https://github.com/tonymillion/Reachability

There are 2 ways to setup the app in your Xcode project.

Part 1 : Getting Reachability to your project

1. Manual

1.1 Check out a copy from the above github url, add the Reachability.h/.m file to your project

2. Cocoapod

2.1 Add the following line to your pod file, pod ‘Reachability’

2.2 Run pod install on terminal.

 

Part 2: Setting up the SystemConfiguration Framework.

1. Go to the Project -> Targets -> Build Phases tab.

2. Add SystemConfiguration.Framework into your project.

 

Part 3: Codes to set up Reachability to test internet connectivity.

AppDelegate.h 

Import the Reachability.h, at the very top of the file.

#import “Reachability.h”

AppDelegate.m

Within the method,

– (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

Add the following codes

 Reachability *reachability = [ReachabilityreachabilityWithHostname:@”http://localhost:3000/”];

    

    reachability.reachableBlock = ^(Reachability *reachability) {

        NSLog(@”Network is reachable.”);

    };

    

    reachability.unreachableBlock = ^(Reachability *reachability) {

        NSLog(@”Network is unreachable.”);

    };

    

    // Start Monitoring

    [reachability startNotifier];