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 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.

 

 

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];

Popovercontroller for Iphone

I was searching for a good community control for the popoverviewcontroller seen on the ipad.

I present to everyone, .

It was so simple to get started with the above and you can remove the complexity in the developing customize UI and get along with your actual development work.

Steps to get it working.

1. Add the following files

  • FPPopoverController.h
  • FPPopoverController.m
  • FPPopoverView.h
  • FPPopoverView.m
  • FPTouchView.h
  • FPTouchView.m
  • ARCMacros.h

2. Add the following codes in your IBAction event.

ViewController *content = [self.storyboard instantiateViewControllerWithIdentifier:@"home"];


FPPopoverController *popover = [[FPPopoverController alloc] initWithViewController:content];
popover.arrowDirection = FPPopoverNoArrow;


[popover presentPopoverFromPoint:CGPointMake(self.view.center.x, self.view.center.y - popover.contentSize.height/2)];

Lastly, do check out the demo included in the git checkout!

[UIPopoverController initWithContentViewController:] called when not running under UIUserInterfaceIdiomPad.’

[UIPopoverController initWithContentViewController:] called when not running under UIUserInterfaceIdiomPad.’

I finally got time to start working on some weekend IOS project and I am starting to get rusty with my IOS language.

Started one of my older project and tried to get going but hit an error i thought was pretty base.

Basically this error is associated with the UIPopoverController and you are running the simulator in iPhone mode and not in iPad mode.

Hope that helps anyone who face the same issue.

Xcode : Unknown class in Interface Builder file

Error : Unknown class in Interface Builder file

This error normally occurs when you have more than 1 target and the newly created file (.m) is not in the Complied Source.

To resolve this, access the Targets in your xcode and make sure that the newly created .m file is within the complied source by adding it in.

Do a run again, everything should work fine.