Sunday, March 30, 2014

Creating rounded ImageView in iOS app development

Implement CirclularLayer will form a rounded image  view



#import <QuartzCore/QuartzCore.h>

@interface CirclularLayer : CALayer
-(id)initWithImage:(NSString*)image WithFrame:(CGRect)frame;


@end


//
//  CirclularLayer.m
//  ImageViewFrameSample
//
//  Created by Mayu on 3/31/14.
//  Copyright (c) 2014 NCS. All rights reserved.
//

#import "CirclularLayer.h"

@implementation CirclularLayer

-(id)initWithImage:(NSString*)image WithFrame:(CGRect)frame{
    
    self=[super init];
    if (self) {
        
        self.cornerRadius = 16.0;
     
        self.borderWidth=4.0;
        self.borderColor = [UIColor darkGrayColor].CGColor;
        
        float heightOfImageLayer  = (CGFloat)frame.size.height;
        float widthOfImageLayer  = (CGFloat)frame.size.width;

        heightOfImageLayer = floorf(heightOfImageLayer);
        widthOfImageLayer=floorf(widthOfImageLayer);
        self.cornerRadius = heightOfImageLayer/2.0f;
        self.frame = CGRectMake(frame.origin.x, frame.origin.y, heightOfImageLayer, heightOfImageLayer);
        
        
        [CATransaction begin];
        [CATransaction setAnimationDuration:0];
        self.contents = (id)[self getImage:[UIImage imageNamed:image]].CGImage;
        [CATransaction commit];
        
        
    }
    
    return self;
}

-(UIImage*)getImage:(UIImage*)image{
    
    UIImage *finalImage = nil;
    UIGraphicsBeginImageContext(image.size);
    {
        CGContextRef ctx = UIGraphicsGetCurrentContext();
        CGAffineTransform trnsfrm = CGAffineTransformConcat(CGAffineTransformIdentity, CGAffineTransformMakeScale(1.0, -1.0));
        trnsfrm = CGAffineTransformConcat(trnsfrm, CGAffineTransformMakeTranslation(0.0, image.size.height));
        CGContextConcatCTM(ctx, trnsfrm);
        CGContextBeginPath(ctx);
        CGContextAddEllipseInRect(ctx, CGRectMake(0.0, 0.0, image.size.width, image.size.height));
        CGContextClip(ctx);
        CGContextDrawImage(ctx, CGRectMake(0.0, 0.0, image.size.width, image.size.height), image.CGImage);
        finalImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    }
    
    
    return finalImage;
    
}




@end

Character oriented programing in iOS game developemnt

I have started doing gaming apps in iOS platform using cocos2d framework.But I found something fishy in the game architecture and I would like to share with you all.

So far we came across how object oriented programming bring simple meaning to sophisticated system.But Its not that simple any more when the system grows up in a large picture.So we need to create something powerful than a simple object,which I called as Character in gaming. 

A Character can be created by special features,behaviour to each other ,time controllability,collision controllability etc.

For example in the gaming scenario,game can be implemented by defining its story plot,where many game characters acts on a scene and so on.
So its highly preferable talk in terms of character to easy the development,reduce the program complexity,reduce the execution time and so on.

So In a complex program I suggest to look close what that application all about and talk in terms of its character.

Thursday, August 1, 2013

MDM-APNS Pusher JAVA

I created MDM APNS Pusher library for JAVA.
Download
Using this library you can send APNS "wake up " to many devices.

**********Please follow these steps to implement it.****************

1.Initialing with certificate-location and password

APNSInitiator apns=new APNSInitiator("/home/mayuran/workspace/IOSMDM/src/certificates/MDM_ WSO2 Inc_Certificate.p12", "pasword");

Note:Here you push certificate should be in .p12 format with its respective password.

2.Calling the method to push

apns.pushingToAPNS(devicesInfoList);

Note: Here devicesInfoList is the set of devicetokens,magictokens .
example :
[{magictoken=7DDAFFA8-B282C-45CB-B3C2-7B71850F1803, devicetoken=L6lUGSrOIx5jnHtQgAWqBELzpkXhGexWiHVHfC2fzwZ8=}, {magictoken=7DDAFFA8-B82C-45CB-B3C2-7B71850F1803, devicetoken=L6lUGSrOIx5jnHtQgAWqBELzpkXhGexWiHVHfCfzwZ8=}]



additional information :
you can create devicesInfoList by

Map<String,String> device 1 Attributes = new HashMap<String, String>(){{
   put("devicetoken", "L6lUGSrOIx5jnHtQgAWqBELzpkXhGexWiHVHfCfzwZ8=");
   put("magictoken", "7DDAFFA8-B82C-45CB-B3C2-7B71850F1803");
}};

ArrayList<Map<String,String>> devicesInfoList = new ArrayList<Map<String,String>>(10);
devicesInfoList.add(device1 Attributes);
devicesInfoList.add(device2 Attributes);
      






        

Monday, July 15, 2013

iOS Mobile Device Management


Over the air Mobile Device Management support – iOS

iOS Enterprise ready?

iOS has OS level implementations of kernel APIs(secured) to support Mobile device management. But these APIs are not publicly available or exposed until it’s triggered from a process called “MDM Enrollment”.
Because apple believes it's too risky to expose device management APIs to user phase.

In addition to that,”MDM Enrollment”provides a highly secured data transmission between the device and server(iOS Middleware).  


iOS MDM






















                                                              
                                                                                  Fig 1

Here are the three steps to trigger to support MDM
1. Basic Authentication phase
2. Certificate enrollment phase
3. Device configuration phase

Basic Authentication Phase
1.In this process a URL is exposed to user from iOS Middleware (Figure1).
Once the user taps the URL ,it ask the user to enter his user name and password for
authentication. User credentials are checked with MDM Directory service(Figure1).

2. Once the device is authenticated ,a “device configuration profile”(payload) request is sent to
the device. This payload,request the device to send basic device attributes such as UUID,
device version etc.

note: Payloads are property lists(plist),which wrap in XML and send it to the device.

Profile service payload


X.509 Certificate enrollment Phase
Once the device sends its response to profile service(iOS Middleware).this response contains the device attributes ,which then to be sent to MDM(figure 1).

To provide a secure tunnel between the device and iOS Middleware,iOS supports certificate enrollment. At the end of this process a secret X.509 certificate is delivered to device. Device later can use this particular certificate to encrypt valuable data in MDM transaction.
iOS supports SCEP protocol to do this certificate enrollment.

In response profile service delivers a SCEP payload to device. This payload should include SCEP server URL,where device can request a certificate.

SCEP Payload


 device install SCEP payload without any user intervention.
During the installation SCEP payload instructs the device to generate pair keys called private key and public key.
Device keep the private key with itself and use its public key to generate a CSR(certificate signing request)and send it to the SCEP server .
With the public key SCEP server talks to CA and issue a X.509 certificate to the device.
(discussed below)

What's SCEP and how it works ?
Simple certificate enrollment protocol (SCEP) allows server/client to do a secure transaction in a network,to avoid the data modified or seen by anyone.

In this process a client / server / device sends a CSR(included its public key) request to SCEP mentioning the operation as GetCACert(requesting a certificate from CA).

SCEP server has two ways to handle this request.

1.In the presence of Registration authority-RA
Fig 2








 In this method SCEP sends its request to RA,RA validates and authenticates the SCEP
request and send a request to CA. In response CA issues a digital certificate.  

 2.In the absence of Registration authority-RA





















In this method SCEP directly talks to CA and gets a digital certificate.

Once the certificate is issued by CA,then it sends that to a operation called PKIOperation. In this
issued certificate first its encrypted and then signed using PKCS7 format,and form a X.509
identity certificate. This X.509 certificate is sent to device and get installed without user intervention. Later this certificate is used to encrypt payloads for secure transaction.

X.509 certificate :
It’s encrypted and signed certificate.
Each apple devices gets their respective X.509 certificate.
Because of its uniqueness , data encryption can be achieved. I will discuss this in next phase.

Encrypted Profile Phase

Device sends its own X.509(received from SCEP server)to profile service in iOS Middleware .
This certificate is used to encrypt MDM configuration payload and results a encrypted data. Later this encrypted data is signed using server(iOS Middleware) credentials and send back to device.
In the device end,encrypted data can be decrypted using its own private key and obtain the original MDM configuration payload and install without any user intervention.

Note: Other devices or third parties in the Internet can not see data since its encrypted using a particular device certificate.

MDM configuration payload



Device in response sends an acknowledgment to the iOS Middleware and perform a check in to the server.
In this acknowledgment response, device sends three tokens to the server

1.Device token -device identity.
2.Push magic token-unique MDM server sends with each push request
3.Unlock token-an escrow key used to clear the passcode on the device.

These three tokens are sent to MDM directory service and saved against user credentials.

How to do control iDevice from MDM?

 Fig 4

To do an operation on device ,MDM directory service sends Device unique token and push magic
token to APNS pusher service.
Now APNS pusher service sends a command to Apple APNS cloud ,which then give a “wake up call” to device.

APNS push service sample given below















 Note: you need to have a Apple MDM push certificate to do this push operation.
           Register MDM APNS

Device then sends a request to Payload service ,mentioning its state (Idle).This request actually invite Payload service to send further commands (such as device lock,wipe,etc) to the device.

In the Payload service end,it asks the MDM directory service for the operation to be performed on the device.
Once the operation (say LOCK) command is received in Payload service,it creates a XML based property list(plist).And it sends it to the Device.

Sample payload for LOCK operation is given below.



Now the device is performed the operation (locked ) over the air command. Same as other operations are performed on the device.

At last device sends an acknowledgment signal,mentioning its state(Acknowledgment) to server side about the status of the operation it performed.


**************************************** End ************************************


Mayuran.K
Software Engineer -WSO2 Mobile Inc
Mobile: + 94 778174806