Thursday, March 23, 2017

Fun with Gradle

Hi All,

Greetings for the day!!!

Have been wondering from many days as to why should I use Gradle if same features are provided by xcodebuild also

  • A command line tool provided by Apple that creates builds/packages.
  • It can take input target, scheme, ipa name, signing information etc in the arguments.
  • Supports multiple tasks and environments.
  • Can be integrated with Jenkins too.


Then why Gradle??
  • Build Management along with Dependency Management. Xcodebuild can only do build management and for dependency management it needs Cocoapods.
  • If you are working on multiple platforms like iOS and Android then Gradle is the common choice for both.

Now how to Use Gradle with Xcode

  • In terminal java -version should be 7 
  • if not type $ brew cask install java  or $ brew cask install Caskroom/versions/java7
  • Download gradle via homebrew $ brew install gradle
  • Type $ gradle -v to check its version

2) Create build.gradle file for your project.
3) Navigate to project directory in terminal.
4) $ gradle build
5) Project builds
ta da....


Sample build.gradle file

plugins {
  id "org.openbakery.xcode-plugin" version "0.14.5"
}

xcodebuild {
     target = 'Hello-Gradle'

/* If need to differentiate between iOS and android */
     type = 'IOS'             

/* Set ipa file name*/
     ipaFileName = ipaName 

 /* if u wish to create archive its necessary to set simulator as FALSE coz for archive we need DEVICE*/
     simulator = false        
}


To execute above file code you can also use:

$ gradle xcodebuild 

Wednesday, March 22, 2017

Fun with Collection Views



Hi all,

Lets start the new year with some fun. I was always interested to create grid like structures in my app and for many times i tried third party tools to fulfill my need but this time i decided to work with Apple's UICollectionView and trust me its awesome.

I know its easy for many who have worked with them but for those who haven't here is a path to start.
You want to show a grid view layout on your view controller. For this we need 3 things :

1) UICollectionViewCell               : This will decide the UI of the grid controls
2) UICollectionViewFlowLayout : This will provide the UI placements and positions
3) UICollectionViewController    :  This will help in UI rendering


First of all create a class named "CollectionViewCell" that is derived from UICollectionViewCell.
This class must have an attached XIB [though u can create programmatically too]. :)

CollectionViewCell.h



CollectionViewCell.m



CollectionViewCell.xib

CustomFlowLayout.h



CustomFlowLayout.m







CollectionViewController.h




CollectionViewController.m





Now here we set the collection view info


The important collection View DataSource Methods









Compile & Run the App
  &
Here is the final cartoon grid view





Tuesday, March 21, 2017

Packaging via ICEBERG in 10 Steps


Hi all,

Learned a new thing today.
Thought of sharing it.

Hope you like it!!!!

If you are willing to create installer packages then ICEBERG by WhiteBox is the right choice for.

Lets follow the simple steps

Step - 1 : Download Iceberg.dmg from Whitebox
Step - 2 : Once downloaded install it.
Step - 3 : This does not comes with default screen instead a top menu bar would be visible



Step - 4 : Click on File and then New Project
Step - 5 : Choose Package from Core Template and click Next

 




Step - 6 : Select the Project Name and directory location. ~/ is the default location of users Home directory.





Step - 7 : The default interface becomes visible with all the default settings. Will be shown via images.  
Do not change any default settings as of now. 
Jump to Files section






















































































































































Step - 8 : Now in Files section
Drag and drop the folder which contains all the files you need to add in package.





Step - 9 : Go to Build menu and click Build or CMD + B. You can see a success here.



Step - 10 : Now where is the package saved??? YES you got right. The default location u chose.






Enjoy and have fun with packaging :)

Friday, March 3, 2017

FFMPEG : Invoke terminal commands from Objective C


Hi all,

Greetings for the Day!!!!

FFMPEG binary downloading and sandboxing in an app is already covered in previous posts.
Now its time to use the binary.

Lets start....


- (void)startTerminalTask
{    
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
      ^{
             NSString *str = [[NSBundle mainBundle] pathForResource:@"ffmpeg" ofType:@""];
                       
             terminalTaskForVideoCapture  = [[NSTask alloc] init];
             terminalTaskForScreenCapture = [[NSTask alloc] init];
                       
             [terminalTaskForVideoCapture setLaunchPath:str];
             [terminalTaskForScreenCapture setLaunchPath:str];
                                     
             NSArray *argumentsForVideoCapture = [NSArray arrayWithObjects:
                                                  @"-f",@"avfoundation",
                                                  @"-framerate",@"30",
                                                  @"-i",@"0:0",
                                                  @"-vcodec",@"h264",
                                                  @"-acodec",@"aac",
                                                  @"-ab",@"64000",
                                                  @"-ar",@"48000",
                                                  @"-ac",@"2",
                                                  @"-f",@"flv",
                                                  self.streamingUrl,nil];
                  
             NSLog(@"argumentsForVideoCapture : %@",argumentsForVideoCapture);
                    
             [terminalTaskForVideoCapture setArguments:argumentsForVideoCapture];
             [terminalTaskForVideoCapture launch];
                      
                      
            
             NSArray *argumentsForScreenCapture = [NSArray arrayWithObjects:
                                                  @"-f",@"avfoundation",
                                                  @"-framerate",@"30",
                                                  @"-i",@"1",
                                                  @"-vcodec",@"libx264",
                                                  @"-acodec",@"aac",
                                                  @"-ab",@"64000",
                                                  @"-ar",@"48000",
                                                  @"-ac",@"2",
                                                  @"-f",@"flv",
                                                  self.screenCaptureUrl,nil];
                           
             NSLog(@"argumentsForScreenCapture : %@",argumentsForScreenCapture);
                       
            [terminalTaskForScreenCapture setArguments:argumentsForScreenCapture]; 
            [terminalTaskForScreenCapture launch];
            
   });
}


- (void)stopTerminalTask
{
    [terminalTaskForVideoCapture terminate];
    [terminalTaskForScreenCapture terminate];
}

Xcode Error : Code Object is not signed at all



Hi,

Recently figured it for first time while developing a Mac App.

I assigned the development team and certificate in Xcode, the bundle identifier was also properly set.
Build the app and the Error pops up

Code Object is not signed at all

Searched and finally found : --deep
Yes exactly, add this value for Other Code Signing Flags under Target's Build Settings tab

Build and Run
And BINGO

Happy Coding :)

Thursday, March 2, 2017

Xcode : Breakpoints dont hit


Hiiiii,


Now this is something that majority of people must have gone through. I have gone through it many times and resolved the issue with different tactics every time :P


Solution 1 :





  • Project >> Edit Scheme >> Info Tab.
  • Remember to set Build Configuration as DEBUG.
  • Check Debug executable.



Solution 2:
  • Delete Derived Data
  • Clean and Rebuild project

Solution 3:
  • Open Project Directory
  • Right click on Project file and click Show Package Contents
  • Delete all files except pbxproj files
  • Restart xcode


Hope people find peace :P

Xcode & Undefined Symbols for Architecture x86_64


Greetings to all,


Compiling a cef cocoa project that includes c and c++ code.
This error mentioned below is very common.


Solution :
  • Ensure that Base SDK is set to Latest under Target's Build Settings.
  • Check The Other Linker Flags under Target's Build Settings. Remove any header or library inclusion from here.
  • Add $(inherited) in Other Linker Flag.
  • Check Target membership of the Files.
  • Check Link Binary with Library. You might need to add the required framework.






Hope you guys find it helpful :)