Tuesday, April 8, 2014

iBeacon Setting up a transmittor

Inorder to set up a transmittor, we need to have the Beacon region and a CBPeripheralManager object.
The code is like below

-(void) initBeacon
{
      NSUUID *uuid = [UUID alloc]initWithString:@"05F2F83E-C827-4F00-9FC6-452414CE1343"];
      self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid major:1 minor:1 identifier:@"com.livingmobile"];
}

-(void) transmitBeacon
{
      self.peripheralData = [self.beaconRegion peripheralDataWithMeasureadPower:nil];
      self.peripheralManager = [[CBPeripheralManager alloc]initWithDelegate:self queue:nil options:nil];
}

We need to implement the delegate methods for getting the callback methods of the PeripheralManager. the delegate is  

-(void) peripheralManagerDidUpdateState:(CBPeripheralManager* peripheral)
{
      if(peripharal.state = CBPeripheralStatePoweredOn)
     {
            NSLog(@"Powered On");
            [self.peripheralManager startAdvertising:self.peripheralData];
     }
     else if(peripheralState = CBPeripheralStatePoweredOff)
     {
            NSLog(@"Powered off");
            [self.peripheralManager stopAdvertising];
     }
}

Sunday, April 6, 2014

iBeacon - analysis of AirLocator app

This application demonstrates mainly the below features

1. Region monitoring
2. Ranging
3. Caliberation
4. Configuration

For Region Monitoring, the main class in this is APLMonitoringViewController. This creates and instance of CLLocationManager . It also creates a CLBeaconRegion instance and initializes with the proximity UUID and passes the beacon identifier. Proximity ID is the unique identifier to attach to a specific region retuned by the init API. This mainly to identify various regions application would have created internally.

Proximity UUID is a property unique to each company. In case of Museum, same UUID will be given to all beacons in the same museum. A UUID can be generated by just entering the command uuidgen in the terminal. Major is a value to identify a same set of beacons for e.g. all beacons in the museum of England by the same company can have same major value. Minor is the value used to identify the beacons in the same region but slightly different. For e.g. All beacons in the same museum but in different rooms can have different minor value. it could be room number.

Beacon identifier is just a string and has been given as similar to bundle identifier. This beacon region is given as input to location manager's monitorRegion api. Inorder to stop monitoring a region, we need to call stopMonitoringForRegion API with the beacon information.

When app is not running, OS will invoke the app and call the delegate method didDetermineState with the CLRegionState and the region in which the monitoring is asked to be done. CLRegionState can be CLRegionStateInside if the user entered that region or CLRegionStateOutside if the user gone out of the region.

One item noticed is that if the application is in foreground and application tried to present a local notification, it will come to the application with the delegate method didReceiveLocalNotification.



Friday, April 4, 2014

iOS App Find My iPhone

This feature allows user to find the lost iPhone or iPad or iPod device using iCloud account

I tried to download this app from the store on my iPod device which was on iOS 6.0, it asked whether i want to download an older version. The current version in the store required iOS 7.0 to be installed.

I downloaded this app and logged into iCloud.com and could see a number of Apple apps such as Find iPhone Contacts, Calendar, notes. reminder, pages, numbers, keynote etc.

Soon i entered into the app, it shown me the list of devices inside and their status with the time it pinged to the iCLoud. clicing on the device shown the location in the map. and all of them except two those shown offline where in office

this require the location services to be on for the locate feature to work. However it can still show that it is online.

It also has lock mode and a user can remotely lock that device. If the device is alredy has a passcode, it will lock the device with that code. if not, it will ask user to give a passcode.

If the device is offline at the time of checking on the app, we can set saying notify when this device ocmes online.

Pretty useful feature. 

Tuesday, April 1, 2014

WiFi Configuration on Windows

On Windows the WiFi profile is an XML file. 
In short for managing the profiles on Windows, we may need to write a script file or a utility app that can accept the profile and add the profile 

Below given is some additional info. 

The console utility "netsh" is available in Windows 7 and above and lower windows versions say Windows XP the latest service packs are having this version (If the machine is not having the latest service pack) we need to update. 
The netsh utility allows user to export the wireless profile and import a wireless profile from an xml file. 
Netsh is dealing with the wlan profiles not the lan profiles 

Another approach to use the Wireless LAN API and create a utility that can export and important the wifi profile. 

Basic commands for exporting and importing the WiFi profile on windows are the ones below (using netsh)

Using the API and creating a 

netsh wlan show profiles => shows all the profiles
netsh wlan export profile folder="PATH_TO_FOLDER" name=PROFILENAME

netsh wlan add profile filename="PATH_AND_FILENAME.xml"

Monday, March 31, 2014

WiFi configuration profile for various platforms

iOS & MAC
We can use the .mobileconfig provisioning file for managing the profile which includes 

Android devices 
Based on some searches, the way the Android profile management work is using the Profile management APIs mainly
There are few apps which does this in combination with the server. 


Almost all classes for Management is available from API level 1 onwards (or tow be safe we can assume API level 10 onwards with all its functionality).  Except the WiFiEnterpriseConfig (which is from 18 and above). 

Many of the well known apps which employ the remote management of the WIFI profile utilises an app on the device. For e.g. TeamViewer https://play.google.com/store/apps/details?id=com.teamviewer.quicksupport.market
Also there are a set of apps in the store which takes input from user for the one time configuration of WIFI and auto connect to it when it comes in range. Much similar to how our WFF Android app do. 


Also, we can use the QR code mechanism to generate the WiFI settings. We can encode the WIFI settings in a QR code and distribute. There are a set of QR code generator SDKs available too. Once the WiFi Details are obtained from the QR code, we can provide option to connect to the WiFi using the available APIs. Barcode scanner app for Android already does this. http://www.addictivetips.com/mobile/connect-to-wifi-networks-by-scanning-qr-codes-with-barcode-scanner-android/

Friday, March 28, 2014

Google Drive API

Google drive is Google's File storage and synchronisation service. This service allows user to have cloud based file storage, collaborative editing, synchronization. the files can be stored publically and Google search engine picks it up for search indexing.

Google provides a client software for most of the famous platforms so that the files are syncrhonized periodically. the space available to user on cloud storage is distributed among various applications such as gmail, picasa, docs etc.

a note aside, it was interesting to read that Googles famous web app Google Doc was from a 4 man army company called writely which was acquired by Google. Also, the Google spreadsheet also from another acquired firm 2Web Technologies.

Now getting on to the programming aspects of it. Below are few notes after going through the samples and articles inorder to fully utilize the API features.

For enabling the API, had to go to the Google API console and enable the Drive API. Saw another permission for Drive SDK. enabled that too, but this is not really required unless creating web apps that require Google Drive access.

the below are main APIs availalble in this SDK


GTLQueryDrive => This class is a common query class for various Google drive SDK. 
for e.g. inorder to get the list of files already available, below is the code segment 

GTLQueryDrive *queryDrive = [GTLQueryDrive queryForFilesList];

The Query needs to be sent with the GTLServiceDrive classes's executeQuery Method. This method is a block one which returns the GTLServiceTicket and list of files in GTLDriveFileList parameters. Applications can list the files iterating the GTLDriveFileList APIs. 

Inorder to save contents into a drive file in cloud, below is the procedure. 

[GTLUploadParameters uploadParametersWithData:fileContent MIMEType:@"text/plain"];
GTLQueryDrive *query  = [QTLQueryDrive queryFilesInsertWithObject: self.driveFile uploadParameters:uploadParameters];

 [self.driveService executeQuery:query completionHandler:^(GTLServiceTicket *ticket,
                                                            GTLDriveFile *updatedFile,
                                                            NSError *error) 

This is going to pretty useful feature with the wide variety of APIs available. 

References:

https://developers.google.com/drive/ios/





Wednesday, March 26, 2014

iOS working with Layers

What is a CALayer?

CALayer manages image based content and allows a developer to perform animations on that content. Layers are often backing store for views but also can be used without views to  display content. Layers main job is to draw the contents that we provide but layer itself is having some attributes that can be set such as background color, corner radius etc. Layer itself contain information about the geometry of its contents. This helps to provide transformation,

A Layer can be created by a UIView object or can be explicitly created using [CALayer layer] method. If former, the UIView itself is the delegate and we should not change this relationship. But if it is explicitly created, then we can set a delegate object.

To access the CALayer from a view, the below method can be used

 CALayer *mylayer = myview.layer;

The above is mainly used to draw shadow around an imageview or something like this.

If using CALayer by its own, i.e. do not take from a UIView, we can use any of the subclasses such as CAGradientLayer, CATextLayer, CAShapeLayer, etc.

The below code sets the background frame and the color and the corner radius

self.view.layer.backgroundColor = [UIColor orangeColor].CGColor;
self.view.layer.cornerRadius = 20.0;
self.view.layer.frame = CGRectInset(self.view.layer.frame, 20, 20);

It is also possible to create sub layers for layers. The code is as below for this

CALayer *sublayer = [CALayer layer];
sublayer.backgroundColor = [UIColor blueColor].CGColor;
sublayer.shadowOffset = CGSizeMake(0,3);
sublayer.shadowRadius = 0.3;
sublayer.shadowColor = [UIColor blackColor].CGColor;
sublayer.shadowOpacity = 0.8;
sublayer.frame = CGRectMake(30,30,128,128);

[self.view.layer addSubLayer:sublayer];

It is also possible to give an image to a sublayer. The code is like below. 
sublayer.contents = [UIImage imagenamed:@"myimage.png"].CGImage;
sublayer.borderColor = [UIColor blackColor].CGColor;
sublayer.borderWidth = 2.0

There is also ways to draw custom content inside a CALayer instead of giving the image content to it. the concept is much simiar to drawing in view. We need to declare a delegate and implement the drawLayer:InContext method.