Apple Event Sep 12,2017

Today Apple Celebrated the Apple Event at “Steve Jobs Theatre”. As we expected, apple gave more surprises. Apple Celebrating 10th year of iPhone and released feature phone called “iPhone X/10”

Apple Event New Products:

  1. Apple Watch Series 3
    1. Watch OS 4
    2. Series 3 Cellular build in  (New)
    3. Apple Heart Study (New)
    4. SIRI can talk in Watch
    5. Apple W2 chip in Watch
    6. Display itself has Antenna to LTE, Wifi
    7. Became no. one watch in the world. Rolex moved to second.
    8. Reading Heard Rhythms
    9. Maps to direction
    10. Music has 40 million songs
    11. Available from Sep 29 2017
  2. Apple TV
    1. Apple TV 4K
    2. A10 X Chip
  3. iPhone 8 and 8 Plus
    1. iOS 11
    2. New Glass finishing on front and back
    3. Wireless charging (Qi open stand)
    4. Retina HD Display
    5. iPhone8-4.7” display
    6. iPhone8 Plus-5.5” display
    7. 3D touch
    8. True Tone display
    9. Stereo speakers
    10. A11 Bionic CHIP
    11. 12 MP Camera in iPhone 8
    12. 12 MP dual cameras in iPhone 8 Plus
    13. Augmented Reality
    14. Blue tooth 5.0
  4. iPhone 10/X
    1. iOS 11
    2. Face ID introduced
    3. Edge – Edge Screen
    4. No Home Button
    5. Wireless Charging
    6. Air Power Charger
    7. Super Retina Display
    8. 5.8” display
    9. 2436*1125 and 458 ppi
    10. A11 Bionic neural engine
    11. 12 MP dual cameras
    12. ANIMOJI introduced
Advertisements

Certificate/Public Key Pinning iOS

In this post we are going to discuss about security “Certificate/Public key Pinning” between iOS app and the server.

 

Why we need certificate pinning?

Every iOS application has a communication with the Server through internet. So, there is a possibility to the hackers can hijack the data. So, we need to make the client-server communication more secure. Yes, there is a question will arise that already we are using “HTTPS” why we need Certificate Pinning.

Yes, even the hackers can read the data in HTTPS connections. Because, now the hacking technologies more improved :). So, we need to do secure hand shake to the server. Certificate pining will help us to achieve that.

 

Where we can get the certificate?

Every server will have private certificate to communicate with the Web applications. The web applications also, have the certificates issued by the server. So, Whenever the web application try to make a connetion with the server, the server will identify the secure connection by verifying the certificate.

So, we can get the certificate (.cert) file from the server end. Also, we can download from the browser with the proper web address.

 

Steps to download .cert file from the browser:

  1. Open Safari browser and enter the URL in the address bar.
  2. There you can see the “Lock” icon infront of the “URL”. Click the lock icon
  3. It will show the “Certificate”. Just drop the certificate into the local folder
  4. Import the “server.cert” file to Xcode.

 

Requirements?

  1. Certificate from the server end.
  2. Host url of the server provided by the server end.

 

How to make the secure connection?

  1. Add Alamofire framework to the project through COCOA POD
  2. We can use the “SessionManager.swift” to make the service call from the our application.
  3. We should add the “Certificate and public key” to the Session manager when we prepare the header files.
  4. We can create a custom Session manager (Ex: YSessionManager.swift) inherited “SessionManager” from alamofire session manager class.
  5. We can use the custom session manager instead of Alamofire’s SessionManager.swift.
  6. Find the source code from the custom class “YSessionManager.swift“,

//

//  YSessionManager.swift

//  CertifictePinApp

//

//  Created by Yuvaraj Manickam on 10/09/17.

//  Copyright © 2017 Yuvaraj Manickam. All rights reserved.

//

import UIKit

import Foundation

import Alamofire

class YSessionManager {

    static let sharedInstance = YSessionManager()

    private var manager : SessionManager?

    

    func apiManager() -> SessionManager? {

        if let instance = self.manager {

            return instance

        } else {

            let hostURL = “www.test.com”

            print(“\n HOST URL: \(hostURL)”)

            

            /// Using Alamofire method to generate serverTrustPolicies

            let serverTrustPolicies: [String: ServerTrustPolicy] = [

                hostURL: ServerTrustPolicy.pinPublicKeys(

                    publicKeys:savedPublicKeys(),

                    validateCertificateChain:true,

                    validateHost:true

                )]

             let configuration = URLSessionConfiguration.default

            /// Configuring Alamofire SessionManager.

            self.manager = SessionManager(configuration: configuration, serverTrustPolicyManager: ServerTrustPolicyManager(policies: serverTrustPolicies))     

            /// Checking the session manager instance.

            if self.manager != nil {

                return self.manager

            } else {

                return nil

            }

        }

    }

    

    /// Fetching public keys from avail Certificates.

    private func savedPublicKeys() -> [SecKey]    {

        var publicKeys:[SecKey] = []

        let clientBundle:Bundle? = Bundle.main

        /// Reading Publickeys from Main Bundle using Alamofire method.

        for localKey in ServerTrustPolicy.publicKeys(in: clientBundle!) {

            publicKeys.append(localKey)

        }

        print(“\n PUBLIC KEYS: \(publicKeys)”)

        return publicKeys

    }

}

 

Please let me know your valuable feedback. Thanks. 

Android Development From Scratch-1

Hi Friends,

           I started to learn Android mobile application development. Am sharing my learning stuffs to you. I hope it will be helpful for the beginners who is starting to develop Android apps like me.

What is Android?

           Android is the name of the mobile operating system owned by Google. Android is based on the Linux Kernel and designed primarily for Touchscreen mobile devices such as Smartphones and Tablets.

          Android is an Open Source Operating system for smart devices. The source code for Android is available under free and open source software licenses.

          The first beta version of the Android Software Development Kit (SDK) was released by Google in 2007 where as the first commercial version, Android 1.0, was released in September 2008.

What is Android Applications?

          Android applications are usually developed in the Java language using the Android Software Development Kit. Android applications can be packaged easily and sold out either through a store such as Google Play Store, Opera Mobile Store, and the Amazon Appstore.

           Every day more than 1 million new Android devices are activated worldwide.

           Android applications are the world largest installed mobile OS and growing fast.

Android Versions:

android-versions

Android OS Versions. Courtesy: Recombu

Work Environment Setup:

          Android application development on either of the following Operating Systems –

  •       Windows OS
  •       Mac OS X
  •       Linux

          We required some tools to develop Android applications and the tools can be downloaded from the web.

  •        Java SE Development Kit (JDK)
  •        Android Software Development Kit (SDK)
  •        Integrated Development Environment (IDE)
  •        Android Studio
  •        Eclipse + Android Developer Tools (ADT)

           I personally using and suggesting the Android Studio for Android application development.

Why Android Studio?

  •         Supported by Google
  •         Fast to use and understand
  •         It is providing the Android SDK
  •         SDK manager provides the SDK updates
  •         Providing the code suggestions

       

Android Architecture:

              Android is an open source, Linux-based software stack created for a wide array of devices and form factors. The following diagram shows the major components of the Android platform.

android-architecture

Android Architecture Courtesy: developer.android.com

 

Application Components:

             Application components are the essential building blocks of an Android application. The main components are listed below,

  •  Activities: An activity represents a single screen with a user interface,in-short Activity performs actions on the screen.
  •  Service: A service is a component that runs in the background to perform long-running operations.
  •  Broadcast Receivers: Broadcast Receivers simply respond to broadcast messages from other applications or from the system.
  •  Content Providers: A content provider component supplies data from one application to others on request. Such requests are handled by the methods of the ContentResolverclass. The data may be stored in the file system, the database or somewhere else entirely.

Will share the basic of the code components, memory management in the next post.

Please share your comments if anything missed or if any information is wrong. Thanks.

Ref:

  1. developer.android.com
  2. tutorialspoint.com

iOS 10 developer notes

Hi Team,

Apple Announced iOS 10, Mac OS X Sierra, Watch OS 3,  with new features and some enhancement on the older features.

iOS 10 new Features:

1. SiriKit:

Now we can use Siri services in iOS apps by using Intents.framework. When the user requests our app services through Siri, the iOS Device will forwards those requests to our extension for handling the requests. We can use the classes of Intents framework classes to receive the data from Siri.

Framework: Intents.framework

2. Proactive Suggestions:

Earlier if we want to adopt our app search, we gave users access to activities and content deep within our app through Spotlight and Safari search results, Hand off and Siri suggestion. From iOS 10, we can provide information what users do in our app, which helps the system promote our app in other places like, Keyboard with QuickType suggestions, Map and CarPlay, the app switcher, Siri interaction and the lock screen. We know that NSUserActivity class provides the option to make our app searchable.

3. Integrating with the Messages App:

iOS 10 allows the developers to create app extensions that interact with the Messages app and let the users send text, stickers, media files, and interactive messages that update as each recipient responds to the message.

Framework: Messages.framework

4. User Notifications:

The User Notification framework supports the delivery and handling of local and remote notifications. The classes of this framework to schedule the delivery of local notification based on the time or location.

Framework: UserNotifications.framework

5. Speech Recognition:

Speech framework provides APIs to convert the Speech to the text. We can perform speech transcription of both real-time and recorded audio.

Framework: Speech.framework

6. CallKit:

This framework helps the VoIP apps integrate with the iOS device UI and give users a great experience. Also, the user can view and answer the incoming VoIP calls on the lock screen and manage contacts from VoIP calls.

Framework: CallKit.framework

7. App Extensions:

This new OS has new extensions,

  • Call Directory
  • Intents
  • Intents UI
  • Messages
  • Notification Content
  • Notification Service
  • Sticker Pack

Also, iOS 10 has enhancements on the following topics,

  • App Search Enhancements
  • Widget Enhancements
  • Apple Pay Enhancements
  • Security and Privacy Enhancements

Please share your comments and please let me know if I missed anything to mention here. Thanks.

How to make UITableviewCell Dynamic Height and Expand iOS

Many application has dynamic contents to show from the server. Also many applications has a design to show some controls/views when the user selects the cell to expand.

So, we need to calculate the tableview cell height dynamic and assign to the UITableView Datasource and Delegates.

1. Calculate Table Cell Height

CGFloat height = 5.0f;

    // We are calculating the height based on the value..

    if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@”6.0″)) {

      NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];

        paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;

        height += [dynamicString boundingRectWithSize:CGSizeMake([[UIScreen mainScreen] bounds].size.width20, 9999) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont fontWithName:@”Helvetica” size:16], NSParagraphStyleAttributeName:paragraphStyle} context:nil].size.height;

}

    else {

        height += ceilf([dynamicString sizeWithFont:[UIFont fontWithName:@”Helvetica” size:16] constrainedToSize:CGSizeMake([[UIScreen mainScreen] bounds].size.width20, 9999) lineBreakMode:NSLineBreakByWordWrapping].height);

    }

Here is a sample view controller with Tableview integrated..

#import “ViewController.h”

#import “DemoTableViewCell.h”

@interface ViewController ()

@property (nonatomic, unsafe_unretained) IBOutlet UITableView *demoTV;

@property (nonatomic, strong) NSMutableArray *heightArray;

@property (assign) BOOL isNeedToExpand;

@end

static NSString *demoTableCellID = @”DemoTableViewCellIdentifier”;

#define IS_IPHONE5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height – ( double )568 ) < DBL_EPSILON )

#define SYSTEM_VERSION_EQUAL_TO(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)

#define SYSTEM_VERSION_GREATER_THAN(v)             ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

#define SYSTEM_VERSION_LESS_THAN(v)                ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)

#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)    ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

@implementation ViewController

– (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    

    self.title = @”Home”;

    self.isNeedToExpand = NO;

    

}

#pragma mark- Webservice Call

– (void) fetchDataFromServer {

    

    // Storing the dynamic height in an array…

    CGFloat height = 0;

    CGFloat captionHeight = [ViewController calculateDynamicCellHeight:@”Value from server”];

    height = height + captionHeight + 10;

    [self.heightArray addObject:[NSString stringWithFormat:@”%f”,captionHeight]];

}

#pragma mark- UITableview Delegate

– (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;

}

– (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 4;

}

– (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    

    // Here you can handle the dynamic height from an heightArray values..

    

    if (self.isNeedToExpand) {

        if ((indexPath.row == 2) || (indexPath.row == 1)) {

            return 110;

        } else {

            return 50;

        }

    }

    return 50;

}

– (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    

    DemoTableViewCell *cell = (DemoTableViewCell *) [tableView dequeueReusableCellWithIdentifier:demoTableCellID forIndexPath:indexPath];

    

    if ((indexPath.row == 2) || (indexPath.row == 1)) {

        cell.hiddenLabel.hidden = NO;

    } else {

        cell.hiddenLabel.hidden = YES;

    }

    

    return cell;

}

– (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    

    // Here you have to handle the indexPath which needs to be expand based on the height..

    

    [self.demoTV beginUpdates];

    if ((indexPath.row == 2) || (indexPath.row == 1)) {

        self.isNeedToExpand = YES;

    } else {

        self.isNeedToExpand = NO;

    }

    [self.demoTV endUpdates];

}

// We are calculating the dynamic cell height based on the string…

#pragma mark- Calcualte Cell Height

+ (CGFloat) calculateDynamicCellHeight: (NSString *) dynamicString {

    

    CGFloat height = 5.0f;

    // We are calculating the height based on the value..

    if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@”6.0″)) {

        

        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];

        paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;

        

        height += [dynamicString boundingRectWithSize:CGSizeMake([[UIScreen mainScreen] bounds].size.width20, 9999) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont fontWithName:@”Helvetica” size:16], NSParagraphStyleAttributeName:paragraphStyle} context:nil].size.height;

        

    }

    else {

        height += ceilf([dynamicString sizeWithFont:[UIFont fontWithName:@”Helvetica” size:16] constrainedToSize:CGSizeMake([[UIScreen mainScreen] bounds].size.width20, 9999) lineBreakMode:NSLineBreakByWordWrapping].height);

    }

    

    return height;

}

– (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

@end

The above source code is just for an idea about dynamic height and expanding cells. Ourself we have to manage the cell views as per our requirement.

Hope it will help someone. Happy Coding. Thanks.

How to check Internet connection in iOS apps?

Hi Coders,

Am going to explain about to manage the Internet check in Xcode projects. Apple providing the “Reachability” class to manage the Internet connection and connection status.

Here you can download the “Reachability” class files.

Follow the steps in Xcode project:

1. Import “Reachability” class files both .m and .h into the project

2. I have one Singleton class file named “MyAppManager”. There I Imported “Reachability.h” file

3. Create a  BOOL method like below,

    In .h file:

      + (BOOL) checkForInternetConnection;      

    In .m file:

  + (BOOL) checkForInternetConnection {

    Reachability *reachabilityObj = [Reachability reachabilityForInternetConnection];

    NetworkStatus status = [reachabilityObj currentReachabilityStatus];

    

    if (!status == NotReachable) {

        return YES;

    } else {

        return NO;

    }

}

4. In the ViewController class import “MyAppManager.h” file

5. Add the code like below to check the Internet connection,

 

if ([MyAppManager checkForInternetConnection]) {

NSLog(@“Internet connected”);

} else {

NSLog(@“No Internet Connection. Please check your Internet connection”);

}

6. Here we can manage the API Call or other stuffs.

Hope it will help you lot. Please share your comments and feedback. Thanks.

Happy Coding!

Yuvaraj Manickam

How to compare two NSDate values in iOS app?

Hi coders,

Now am going to post about to compare two NSDate values in iOS.

We all know well to compare two NSString values but recently I came to know about to compare two NSDate values ha ha…
Am going to share with you all about that,

NSDate *today = [NSDate date];
NSDate *compareDate = [NSDate dateWithString:@”your date”];

NSComparisonResult compareResult = [today compare : compareDate];

if (compareResult == NSOrderedAscending)
{
NSLog(@”CompareDate is in the future”);
}
else if (compareResult == NSOrderDescending)
{
NSLog(@”CompareDate is in the past”);
}
else
{
NSLog(@”Both dates are the same”);
}

 

This is the simple way to compare two Date Values. Please share your feedback on this.

Happy Coding!

Warm Regards,
Yuvaraj Manickam