Thursday, December 15, 2016

Module Integration imposes Swift Version Issue


Hi All,

Recently I tried to a a third Party Library to my iOS Project.
This library was built on Swift 3.0

On Integration I got Error :

Module compiled with newer version of Swift language (3.0) than previous files (2.0) for architecture x86_64 


To Overcome this tried following things:

  • Target
  • Build Settings
  • Swift Compiler - Version
  • Set No to Use Legacy Swift Language Version


Clean and Build and you are good to GO
:)

Thursday, October 13, 2016

The Charming FFMPEG


Hi All,

I have been using FFMPEG from almost 5 years.... I Am Loving it :)
Finally thought of sharing info about it when being used in OSX


1) Installation via HomeBrew

  • Open Terminal 
  • Install HomeBrew : Follow HOMEBREW
  • Install FFMPEG   :   brew install ffmpeg --with-fdk-aac --with-ffplay --with-freetype --with-frei0r --with-libass --with-libvo-aacenc --with-libvorbis --with-libvpx --with-opencore-amr --with-openjpeg --with-opus --with-rtmpdump --with-schroedinger --with-speex --with-theora --with-tools         
  • To Update HomeBrew : brew update
  • To Update FFMPEG   : brew upgrade ffmpeg                             


2) FFMPEG Builds


3) FFMPEG Binaries
  • http://www.ffmpegmac.net/ [Follow MAC]


Enjoy FFMPEGing... :)


Tuesday, May 17, 2016

Convert image to base64 Format


Hi Guys,

Recently I played with conversion of NSImage to base64 format so thought of sharing with you all.
Here you go..

NSData   *data = (NSData*)[self.myImageView.image TIFFRepresentation];

NSString *str    = [data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];

Hope you like it :)

Friday, April 8, 2016

Unit Testing in iOS


Hey Folks,

I enjoyed working with Unit Testing. So decided to make a demonstration for you all.
Hope you find it helpful.

What is Unit testing
    • The smallest part of any software development task in which the units are tested for proper and smooth workout. 
    • It can be done manually and automated too.

    Why should I write Test Cases or do Unit testing
    • Helps to define a problem and find all its positive & negative solutions.
    • Gives better understanding of each small task or code.

    Things that should definitely be covered or tested in a Unit Test
    • Boundary Values
    • Expected Values
    • Stress Testing for Loops
    • Out of Bound values
    • Nil / NULL check

    Working with OCUnit in XCode
    • OCUnit is built in XCode
    • When you check Use Unit Testing on New Project template wizard the setup is already done for you.

    Lets start by Adding Unit Test Target to an existing project
    • Right Click on Target
    • iOS
    • Test
    • Choose iOS Unit Testing Bundle


    Working on New Project with Test Targets
    • Start xCode
    • Choose a Single View Application
    • Choose options for your new project
    • Remember to check on "Include Unit Tests"

    • This is the Project Navigator



    • This is the sample code structure available for Test file 



    XCTestCase Class
    • It is a subclass of XCTest and is the Override points for writing test cases
    • This class can have multiple methods & supports the Setup & TearDown methods
    • Setup & TearDown methods execute BEFORE & AFTER every test method
    • Test methods are instance methods
    • Test methods accept NO PARAMETERS & have NO RETURN VALUE
    • Test methods are prefixed with "test" keyword
    • Being prefixed they are automatically recognized as test methods by the framework

    How to add XCTestCase Class Files
    • Right Click on Tests
    • New File
    • iOS
    • Source
    • Unit Test Case Class 
    • Provide a Name, must be suffixed with keyword Tests

    Some Testing Code
    • To compare Objects
                             XCTAssertEqualObjects(String to compare, my string, @"comments");
    • To check date accuracy or precision of values
                            XCTAssertEqualWithAccuracy(Date to compare, date that I set , 0.001);
    • To check if dictionary has nil value
                            XCTAssertNotNil(dict);
    • To Check true / false value
                            XCTAssertTrue(BOOL value returned from any method,
                                                      @”Can be used for conformsToProtocols”);

                            XCTAssertFalse(BOOL value returned form  method,
                                                      @"Generates a failure when ((a expression) != false)");
    • To test performance or execution Time
                            [self measureBlock:^ { [self anyMethod]; } ] ;


    How to Execute Tests
    • Command + U
    • OR Product > Test

    View status of all Tests executed
    • The Green Tick indicates the Success.
    • If it is Red then it indicates an Error.
    • Same images appear in reader view before each method


    Enable XCode Code Coverage Reports
    • Product > Scheme > Edit Scheme
    • Choose Test Scheme > Tick "Gather Coverage Data"


    View Reports in XCode
    • Command + 8
    • OR View > Navigators > Report Navigators










    Some Info...
    • What happens if i remove Setup and tear down?? 
    • No issue arises
    • Can I run single test?? 
    • YES, you can :  Control-Option-Command-U
    • Running xCode Tests from Terminal
    • xcodebuild test -scheme OpenPage2 -project OpenPage2.xcodeproj -configuration Debug -sdk iphonesimulator
    • It clearly states that  Unit Tests are not supported by the Simulator. To avoid this add TEST_HOST='' to the end of the xcodebuild command. 
    • Run the tests from the terminal again. 

    Hope you find it helpful :)

    Wednesday, April 6, 2016

    Handling Multiple Targets & Environments in iOS


    Hey Folks,

    Finally writing something that I wanted to do from long time.
    Handling multiple targets in an iOS Project that deal with multiple environments.

    Lets Start.

    1) Create a New Project or you can start with an existing Project.
        I will be using new one named HelloGradle which I will be using in Gradle integration also.

    2) So in my Project i was provided with a default target as HelloGradle. I renamed it as "A".

    3) Now lets add more Targets.

    • Click on Project.
    • Right Click on any Target.
    • Duplicate.
    • Rename it as "B".
    • Perform this task to add more Targets. I added 6 in total "A - F".




    4) Name still not changed : You will observe that Target names are still not changed at all places
    Go to Manage Schemes. It will show all targets. Select a Target press Enter change Name and Press Enter.




    5) Now rename the plist files associated with each Target.
    • Click on Target.
    • Build settings.
    • Packaging.
    • Rename plist file for all targets as A-Info.plist , B-Info.plist .......... F-Info.plist.


                                                             



    6) Build and Run : It will work fine as usual. Currently there are only 2 build Configurations namely "Debug" & "Release"

    7) Now I wish to add Multiple Build Configurations or you can say Environments. 
        Remember : Build configurations are project wise not Target wise.
    • Project
    • Go to Info Tab
    • Click Editor
    • Add Configuration
    • Duplicate Debug Configuration

    OR
    • Click + below Configurations
    • Duplicate Debug Configuration




    8) Now we have multiple Targets & multiple Build Configurations 




    9) Now the question arises how to store environment specific values. For this do this..
    • Create plist for all Environment & for all Targets. 
    • Ensure that name of plist file remains same.
    • Have a look @ the structure.
    • Remember to follow the naming conventions.
    • Inside plist file you can add values that are environment specific.
    • Remember to add one value in all plists ENVIRONMENT : TARGET_Dev / TARGET_QA / TARGET_Prod depending on Target & environment folder.


    10)  Now to establish relation between plist file and build configuration
    • Target
    • Build Settings
    • Click on + next to  ALL | Combined | Levels + 

    • Add User defined Settings
    • Name it as Build_Env
    • Provide values as shown in below image



    11) Choose any Build Configuration from Edit Scheme
    12) Build & Run your project
    13) And you are Done
    14) Now from AppDelegate read your environment.plist file and set values accordingly.



    Hope you did not find it BORING :P







    Tuesday, April 5, 2016

    Creating Profiles & Certificates for iOS


    Hey Folks,

    This tutorial gives you basic info of the Developer account for creating profile & certificates etc..

    Lets StartCreating profiles & certificates
    • Open developer.apple.com
    • Click Member Center
    • Provide Apple Developer credentials & Log in
    • Click Certificate , Identifiers , Profile








    ==================================================================

     Certificates


    ********************************* Step - 1 *********************************




    ********************************* Step - 2 *********************************

    Choose between Development & Production


    ********************************* Step - 3 *********************************



    ********************************* Step - 4 *********************************



    ********************************* Step - 5 *********************************

    Your Certificate is created and now you can download it


    =============================================================


    App ID

    ********************************* Step - 1 *********************************



    ********************************* Step - 2 *********************************


    ********************************* Step - 3 *********************************

    Click to Continue & its done


    =============================================================


    Provisioning Profile


    ***************************** Step - 1 ******************************





    ********************************* Step - 2 *********************************




    ********************************* Step - 3 *********************************




    ********************************* Step - 4 *********************************

    Click to Download


    =============================================================

    Devices

    • Provide Name, UDID and you are DONE with devices.
    • You can add a max of 100 devices. However people say that if u drop a mail to Apple they may increase your quota of devices for FREE but haven't tried for it.



    Thanks to all :)

    Friday, April 1, 2016

    Hands On with PCH File in IOS


    Hey Folks,

    All people working on iOS must have come across this file. Lets dive in it for all its pros and cons

    What is PCH File?

    • Pre-Compiled Header File
    • Prefix headers are compiled and stored in a cache, and then automatically gets included in every file during compilation & lets you include a file without adding an import statement to it. So rather than parsing the same header files over and over, these files get parsed once, ahead of time.

    Naming Convention
    • ProjectName-Prefix.pch

    Positive Face
    • Precompiling the prefix header will be most effective if the contents of the prefix header or any file it includes change rarely.
    • They make compiling faster.

    Negative Face
    • If the contents of the prefix header or any file it includes change frequently, there may be a negative impact to overall build time.
    • Avoid adding Macros.
    • If you transfer your file to any other project then it may not compile as many dependent headers that were added in PCH are not available @ different location and you need to check the actual one from PCH headers list. This could be a tedious task for Large projects.
    • People have one funda >> Adding headers in PCH saves header importing typing time.

    Can i compile my project without PCH file
    • YES, Ofcourse

    How to add PCH file if not provided
    • Right Click on Project
    • New File
    • iOS > Others > PCH file
    • Provide name as ProjectName-Prefix.pch
    • Save in ProjectName Folder
    • Target > Build Settings > Search for Prefix Header and Provide Name







      Hope you all enjoyed it :)



      Thursday, March 31, 2016

      < Angular > & " Quotes " Import in iOS


      Hey Folks,

      I have seen many times people discussing on this matter so today i thought to write my own views on it.
      • Objective C has grasped this from C / CPP
      • Quotes" " indicates searching header in local / current working directories and if it doesn't find a match then moves on to check the system paths    whereas Angular's < > are used for searching in System Headers.

      #import <something> : compiler looks in all include directories.
      #import "something"  : compiler looks only in the directory of the file with the include in it.


      Both ViewController & Analytics header exists within my local project directory so using Quotes to add them





      UIKit is a System Header so accessing using Angular braces. However they can be accessed via Quotes as well :)




      Hope i made it clear to some extent :)




      Wednesday, March 30, 2016

      Flurry Wonders for iOS


      Hi @ll,

      M back again with another Analytics Tool.
      Please welcome Yahoo's "FLURRY"

      Bit slow as compared to Google Analytics but has features that that can fulfill your app's requirements.

      Things to do with Flurry : 
      • Analytics
      • Ads
      • Crash Reporting
      • integration for iPhone / iPad / iWatch

      Working with Analytics :

      To get a deep insight of the App's usage Flurry's Analytics service is provided

      Step-1 : Get your API Key & SDK

      • Choose your platform



      • Provide App Name & category


      • Verify your account


      • Get your unique application key


      • Download required SDK and Unzip to get details


      • You can view all your apps in the dashboard

      ===================================================================

      Step-2 : Integrate SDK in project

      • Now open your project which contains a single ViewController that captures events when user arrives on the screen or when user clicks YES or NO buttons


      • Right click on your project >> Add Files >> Choose Flurry >> Done 


      • Now lets start by importing FLURRY in AppDelegate 

      • Mention your Unique key in didFinishLaunchingWithOptions

      • Open you view controller and again import Flurry.h





      • Build and Run your project and you will see this.... "ERRORS"


      • Don't worry and add SystemConfiguration.framework from Target >> General >> Linked frameworks & libraries






      • Now run the project & it will work fine and start logging events. :)

      ===================================================================

      Step-3 : Check Dashboard for Event Logs
      • You can check the dashboard for all info.Please wait for 1-2 hrs so that data gets reflected in Analytics


      Hope it provides you basic idea of Flurry analytics and you dig in more for other features like crash reporting and Ads.
      Enjoy and have fun with Flurry
      :)

      Monday, March 28, 2016

      A Day with "Google Analytics"


      Hey Folks,

      Today got a chance to work on with Google Analytics.
      Amazing...
      Loved playing with it.

      Presenting basic info so that you guys can start playing with it too within your iOS Apps :)

      Let's Start..


      A) Accounts & Guides

      • Sign up with an email id
      • Provide an Account name & App name that you want to work with
      • Agree with terms & conditions and you will be provided a TRACKING ID
      • Get your iOS Starting Guide that will help you in adding analytics to your app and screens : “https://developers.google.com/analytics/devguides/collection/ios/v3/"
      • You get a sample app to to start with





      B) App Info

      • Analytics uses CocoaPods to install and manage dependencies.
      • Remember to Choose between Objective-C or Swift
      • Create / Choose App Name
      • Download googleServices-info.plist file and drag into your root folder

       
      C) CocoaPods 
      • Create a text file named as podfile with following content :
      platform :ios, ‘9.1’ 
      use_frameworks! 

      target ‘PullToRefresh’ 
         do  pod 'Google/Analytics' // you can mention all dependencies here
       end
      • Open Terminal and write pod install
      • If you prefer not to use CocoaPods to manage library dependencies, you can download and directly use the Google Analytics Services SDK.


      D) Project

      • Add Analytics inside AppDelegate #import <Google/Analytics.h>
      • Then, override the didFinishLaunchingWithOptions method to configure GGLContext
      • Here you’ll send a named screen view to Analytics whenever the user opens or changes screens on your app. Open a View Controller that you'd like to track, or if this is a new application, open the default view controller.

      - (void)viewWillAppear:(BOOL)animated
      {
          id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
          [tracker set:kGAIScreenName value:@"MAIN SCREEN"];
          [tracker send:[[GAIDictionaryBuilder createScreenView] build]];
      }


      Note: You can add tracking code to every UIViewController that represents a screen, whether shown to your user imperatively (via code) or via storyboard. Set a name inside everyUIViewController if you want to differentiate between screen views for your app in Analytics. All activity recorded on the shared tracker sends the most recent screen name until replaced or cleared (set to nil).


      E) View the Status in dashboard











      Hope it helps :)