Thursday, 17 December 2015

Distribute IOS Apps wirelessly using Your Server

First, select "Build and Archive" from your XCode build menu. Your archived project will be stored in the "Archived Applications" section of the the XCode organizer (Window > Organizer).
Next, select the archive you want to distribute in the XCode organizer and select "Share Application..." at the bottom of the window. Pick the appropriate provisioning profile and then "Distribute for Enterprise".
In the distribution window, enter the title and the full url to the ipa file (where you plan to host your app) for example,
Along with the generated .plist and the .ipa files, you'll need the provisioning profile and a simple index file, for example:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<title>My Cool app</title>
<!-- Art Direction Styles -->

    <li><a href="">
                Install Example Provisioning File</a></li>
    <li><a href="itms-services://?action=download-manifest&url=">
                Install Example Application</a></li>
With these all uploaded to your server all you need to do is point people at the index file and they can select the links to install the provisioning profile and app directly from mobile safari on their iOS devices. A much nicer experience compared to installing through the iTunes sync process.
After re-publishing updates to my apps several times, I was finding it a little tedious to re-type the full url into the XCode tool---plus I could never remember what I named the damn files---so I came up with this quick and dirty index.php script to do the grunt work for me:

$ipas = glob('*.ipa');
$provisioningProfiles = glob('*.mobileprovision');
$plists = glob('*.plist');

$sr = stristr( $_SERVER['SCRIPT_URI'], '.php' ) === false ? 
    $_SERVER['SCRIPT_URI'] : dirname($_SERVER['SCRIPT_URI']) . '/';
$provisioningProfile = $sr . $provisioningProfiles[0];
$ipa = $sr . $ipas[0];
$itmsUrl = urlencode( $sr . 'index.php?plist=' . str_replace( '.plist', '', $plists[0] ) );

if ($_GET['plist']) {
    $plist = file_get_contents( dirname(__FILE__) 
        . preg_replace( '/![A-Za-z0-9-_]/i', '', $_GET['plist']) . '.plist' );
    $plist = str_replace('_URL_', $ipa, $plist);
    header('content-type: application/xml');
    echo $plist;

?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<title>Install iOS App</title>
<style type="text/css">

li {
    padding: 1em;

<!-- Art Direction Styles -->

    <li><a href="<? echo $provisioningProfile; ?>">Install Team Provisioning File</a></li>
    <li><a href="itms-services://?action=download-manifest&url=<? echo $itmsUrl; ?>">
         Install Application</a></li>
t's nothing fancy so you'll probably want to spiff it up but to use it (you'll need PHP), just create a folder and drop in the index.php along with the .mobileprovision file, the exported .ipa and the exported .plist. To make things easy just enter _URL_ (uppercase url with underscores) as the "url" in XCode and the script will automatically fill in the proper URL as necessary. It doesn't matter what the file names are as long as there is only one .moblieprovision.ipa and .plist.

Recursive Closures in Swift

Here we are going to see examples of writing Recursive Closures.

1. Write a function, that will run a given closure for a given number of times


    func repeatTasks(times: Int, task:()->Void)
        for _ in 0..<times {

Calling the method:
      repeatTasks(10) { () -> Void in
            print("swift is great")

2. Write a function that you can reuse to create different mathematical sums


   func mathSum(times:Int, operation:(Int)->Int)->Int
        var result = 1
        for i in 1...times{
        return result;

Calling the method:

  mathSum(10) { (number ) -> Int in
            number * number;

Writing the Same Math Sum using fibonacci series


   func fibonacci(number: Int) -> Int {
        if number <= 0 {
            return 0
        if number == 1 || number == 2 {
            return 1
        return fibonacci(number - 1) + fibonacci(number - 2)

Calling the method:

    mathSum(10) { (number) -> Int in

Custom Closure in Swift for a Service Class

Hi Welcome all to this basic swift closures example

Now lets begin with the actual closure class

typealias CompletionBlock = ((NSData?) -> Void) //like typedef a completionBlockName or alais

class ServiceClass: AnyObject //The class is of type any object
   internal func makeServiceCall(urlToCall:String,completionHandler: CompletionBlock)
        let googleURL:NSURL? = NSURL(string: urlToCall) //Can be nil
        let request:NSURLRequest = NSURLRequest(URL: googleURL!);
        let task = NSURLSession.sharedSession().dataTaskWithRequest(request) { (data, response, error) -> Void in
            print("response is \(response)");
            print("response is \(error)");
            print("response is \(data)");
            if((error) == nil) //Could rather use if let here
                if let finaldata = data

How to invoke there methods are as follows.

    override func viewDidLoad() {
        ServiceClass().makeServiceCall("") { (ServiceData) -> Void in
            if let _ = ServiceData
                print("service data==\(ServiceData)")
                print("service data is nil")

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

Thursday, 21 June 2012

creating a two dimensional CGRECT

 create a instance variable

 CGRect  **ippArray;

//note that status is a two dimension 

then in you view did load method

- (void)viewDidLoad
    [super viewDidLoad];
    ippArray = malloc( 12 * sizeof( CGRect * ) ); //array pointer to the next dimension
    for(int  i = 0; i < 12; i++ )
        ippArray[ i ] = calloc( 8, sizeof( CGRect ) );


The formatting will look like this(roughly) for a 3*2 dimension
Although based on the type of data structure you want you can create any type of memory structure
you want and based on which you can access the elements.

why to go for a texture packer?

Monday, 14 May 2012

Core data and relationship

Everyone this is a tutorial about, creating core data and their relationship, Before you read this you may need some knowledge about creating and using interface Builder,

so lets begin to create a simple core data application and providing them with a relation,
to start with create an empty project in the new project window not a single view based application.

then tick use core data in your application and then click on next and choose a place where you have to create the text.

Now you can notice that core data has already inserted some different set of methods in your app delegate, this is because you have chosen to use core data in your applications.

Now before going further you have to understand three objects:

1.Managed Object context:

The context is responsible for mediating between its managed objects and the rest of the Core Data infrastructure. The infrastructure is in turn responsible for, for example, translating changes to managed objects into undo actions maintained by the context, and also into operations that need to be performed on the persistent store with which the managed object is assignedit is expected that you either keep a reference to the context, or you have a means of easily retrieving it

2.Managed Object model:

An NSManagedObjectModel object describes a schema—a collection of entities (data models) that you use in your application.A managed object model maintains a mapping between each of its entity objects and a corresponding managed object class for use with the persistent storage mechanisms in the Core Data Framework. You typically create managed object models using the data modeling tool in Xcode, but it is possible to build a model programmatically if needed.

3.Persistent store Coordinator:

Instances of NSPersistentStoreCoordinator associate persistent stores (by type) with a model (or more accurately, a configuration of a model) and serve to mediate between the persistent store or stores and the managed object context or contexts.Instances of NSManagedObjectContext use a coordinator to save object graphs to persistent storage and to retrieve model information. A context without a coordinator is not fully functional as it cannot access a model except through a coordinator. The coordinator is designed to present a fa├žade to the managed object contexts such that a group of persistent stores appears as an aggregate store

So, thats the theory part of it read it to understand and then now let us define two classes
Student having the fields-> name, enrollno and sex.
College having fields -> name and skills.

So go to the data model and click add new entity at the bottom of the screen there create two entity
student and college having the fields in the following manner.

Now as you can see we have create two entities student and college, note that we have provided the relationship in it as studyrelation for student and the destination as college and link it with the other relationship in the inverse selection type.  In the next college entity create a studentdetails relationship and we are going to create a to-many relationship because a college can have many student details and then select the destination as student and inverse as study relation.

The to-many relation ship is set in the following manner

Select the to-many relationship, choosing this creates a NSSet in your managed object class college.
Then do the following steps to create the ManagedObjectclass

select the NSManagedObject subclass and select the data model that you are going to use

 the choose the entities that you are suppose to use and select next which create the two classes that u want.

To consume this, create a new view controller , create a new view controller and add two methods, add record and show record and set the windows root view controller to this view controller.

Lets examine the view controller xib and it consists of the following two methods

so create a member variable in view controller as NSManagedObjectContext *context;  and its properties and its corresponding synthesis
@property (nonatomic,retainNSManagedObjectContext *context;
@synthesize context;

Now in the viewdidload method of that view controller do this following inorder to access the context, only through a context can we access everything.

- (void)viewDidLoad
    [super viewDidLoad];

    self.context = [[[UIApplication sharedApplication] delegate] managedObjectContext];


 so with this step now we have obtained the context,

Now to add a record use the following method. 
NSEntityDescription is used to insert the entity in the particular context

-(IBAction) addrecord
    Student                             *stud; //object for student
    College                              *col; // object for college
    NSError                             *error;
    stud                           =   [NSEntityDescription

                                    // used to insert a record in to student entity = @"Messi";
    stud.enrollno = [NSNumber numberWithInt:123]; = @"Male";
    col = [NSEntityDescription insertNewObjectForEntityForName:@"College" inManagedObjectContext:context]; = @"Kamaraj";
    col.skills = @"IOS";
    [col addStudentdetailsObject:stud]; 

//This line links the col by adding an entry to the NSSet of list for the studentdetails relation

    [stud setStudyrelation:col];
//This line link the student with the college using study relation

    if (![context save:&error]) { //save changes
        NSLog(@"couldn't save: %@", [error localizedDescription]);
    } else {
        NSLog(@"inserted successfully");


Inorder to retreive the record we have another method to list the records

The NSFetchRequest is used to fetch a particular record from the given context of records and then it returns all those result for the particular entity in an array

-(IBAction) listrecord
    NSFetchRequest                      *fRequest;
    NSEntityDescription                 *eDesc;
    NSArray                             *arr;
    eDesc                           =   [NSEntityDescription entityForName:@"Student" inManagedObjectContext:context];
    fRequest                        =   [[NSFetchRequest alloc] init];
    [fRequest                           setEntity:eDesc];
    arr                             =   [context executeFetchRequest:fRequest error:nil];
    for (Student *st in arr) {

 // by means of linking from student one can access all the college relations values, so using my relation name i can access the relation names of the other class.

    eDesc                           = [NSEntityDescription entityForName:@"College" inManagedObjectContext:context];
    [fRequest setEntity:eDesc];
    arr = [context executeFetchRequest:fRequest error:nil];
    for (College *cl in arr)


So once can access the college record, from the student record through the use of giving relationship among the classes, where name is the object of college. 

This will add the same hardcoded student name in the core data, you can customize them as per your wish using this.

You can download the copy of the above tutorial using this link
thank you. For doubts and correction please contact me at


Friday, 27 April 2012

UISlider Customisation

Transparent UISlider:

By default there is a default blue and white, selection for minimum and maximum image in iphone, what if you want a transparent image in them without having those images


Add the slider in the interface builder and create an iboutlet for it in the code, then link them together
then in the -viewdidload- method use the following code, to make the UISlider transparent
    UIGraphicsBeginImageContextWithOptions((CGSize){ 1, 1 }, NO, 0.0f);    UIImage *transparentImage = UIGraphicsGetImageFromCurrentImageContext();    UIGraphicsEndImageContext();
    [slider setMinimumTrackImage:transparentImage forState:UIControlStateNormal];    [slider setMaximumTrackImage:transparentImage forState:UIControlStateNormal];

This should help you to get a transparent slider without any minimum and maximum images

Customized Minimum and Maximum Images:

If you want to customize it with your own images, then asusual link them together then in the viewdidload method use the following code.


  UIImage *minImage = [UIImage imageNamed:@"min.png"];
  UIImage *maxImage = [UIImage imageNamed:@"max.png"];
  UIImage *tumbImage= [UIImage imageNamed:@"slidebutton.png"];  minImage=[minImage stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
  maxImage=[maxImage stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
  [slider setMinimumTrackImage:minImage forState:UIControlStateNormal];
  [slider setMaximumTrackImage:maxImage forState:UIControlStateNormal];
  [slider setThumbImage:tumbImage forState:UIControlStateNormal];