Tuesday, January 24, 2017

Cef/Chromium Linker Issues on MAC


Hi All,

I somehow deleted my Cefclient Helper Target. When I decided to make helper target by making a duplicate of  Cefclient Target then faced some issues which are listed below along with their solutions that are quite generic and can be applied anywhere with similar issues.


System Info:
OSX : 10.11.6
XCode : 8.1


Error :
Undefined symbols for architecture x86_64 + "_main", referenced from: implicit entry/start for main executable

Solution :
  • Main method is either commented or missing. Plz add
  • int main(int argc, char * argv[])


Error :
 cef::logging::LogMessage::LogMessage(char const*, int, std::string*) in libcef_dll_wrapper.a(cef_logging.o)
      cef::logging::LogMessage::LogMessage(char const*, int, int, std::string*) in libcef_dll_wrapper.a(cef_logging.o)
      cef::logging::ErrnoLogMessage::~ErrnoLogMessage() in libcef_dll_wrapper.a(cef_logging.o)
libcef_dll_wrapper.a 
ld:symbol(s) not found for x86_64

Solution :
  • C++ Standard Library: libc++ (LLVM C++ standard library with C++11 support)
  • This value should be same for both Library and targets.
  • In my case it was different for my Helper Target.
  • Remember to set the correct architecture.


Hope its helpful :)



Sunday, January 22, 2017

FFMPEG Binary in OSX Package


Hiiiiii All,
Spent my last working day to solve issue related to packaging of FFMPEG binary in OSX release build.Every time i made a package its build correctly but the moment when FFMPEG binary is invoked i get error :

CMSampleBufferGetImageBuffer signalled err=-12731(kCMSampleBufferError_RequiredParameterMissing)

So the way to avoid this error we have to do following steps :
  • Project Settings
  • Click Target
  • Click Capabilities
  • Enable App-Sandbox
  • A file is added in project named Target.entitlements

Inside Entitlements file add following info :
  • com.apple.security.inherit [Boolean] YES
  • App Sandbox [Boolean] YES

Also add a RunScript in Target's Build Phase:

codesign -f -s "your certificate" 
--entitlements ./ffmpeg.entitlements 
./Build/Intermediates/ArchiveIntermediates/App\ Store/InstallationBuildProductsLocation/Applications/<my app>/Contents/MacOS/ffmpeg


Hope it hepls :)

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