Monday, April 28, 2014

What is Apple AirPlay?

Apple Airplay lets user to stream movies or music from iTunes or Mobile apple device to any Airplay enabled device on the same network.

AirPlay has two main components a Source and a Receiver. A Source is device running on AirPlay enabled software. The receiver is an AirPlay compatible device that can stream the file and as well as display information.

the devices must be running on iOS 4.2 or later inorder for it to be a Source. A User can Airplay from computer as well if running on MAC OS 10.2 or later.

Airplay mirroring is a feature where a user can stream the screen from an iPad2 to an HDTV wirelessly and securely without requiring cables.

 Airport protoco is an open source protocol and anybody can implement it to act as a Airport receiver.

Airtunes part of the Airplay protocol stack uses UDP protocol for streaming audio and is based on RTSP streaming protocol. the streams are transcoded using. The streams are transcoded using Apple's lossless codec with 44000khz with two channels encrypted using AES. It was interesting to read that Apple uses a private key to encrypt the and decrypt the stream and that was hacked and made available to the public. 

Now what is the difference between Airplay and Airplay mirroring. 

AirPlay allows user to stream music, video and photos from their iTunes library, iOS devices to computers, speakers, and stereo components, Airport express and Second generation apple TV. Apps must be AirPlay compatible inorder for streaming to work. They must be also on the same network. 

AirPlay mirroring enables users of certain Airplay compatible devices to display whatever is on their device's screen on Airplay-compatible apple TVs. this allows users to show any website or video game or any content on the device screen on an HDTV that Apple TV is attached to. This is again achieved via Wi-Fi (wired mirroring doesnt require Apple TV).

Next part will try to explore the APIs available for the same!

Friday, April 25, 2014

Wearables - JAWBONE

Jawbone is a wearable device manufacturer. They have UP, UP24 writ band devices among other devices. The UP devices help to understand how you sleep, move and sleep so the one can make smarter choices. There is an app associated with this which gives the measure, milestone about the activities and achievements. These devices work with bluetooth low energy to transfer the captured data to the app. The fascinating feature are the ones below

- Insight Engine
- Log work out of all kinds
- Food & Drink tracking
- Sleep tracking
- Smart Alarm + Power Nap => It vibrates when it is appropriate time in your sleep to wake you up so that one feel refreshed!
- Idle alert => It alerts you when it is more idle time!
- Mood tracking => it finds connections and log your moods and determines how you feel for each connection!

Pretty cool features.

Now coming to the APIs for this

the API relies on OAUTH 2.0 protocol for the authentication. A client id and client secret is assigned to each application created by a developer. Developer can seek authorization to access the data and obtain an access token. The token has an extended expiration time and can be used during multiple calls.

Below link lists all the API end points
https://jawbone.com/up/developer/endpoints

the main end points are below:

1. Band Events
2. Body - retrieve, delete, record events for specific body part etc
3. Cardiac - retrieve user cardiac metrics, heart rate, blood pressure,
4. Custom Events - seems like user can define custom event by aggregating many. Need to look into details on this
5. Meals - Get users meals list, details on a specific meal, update, delete a meal event,
6. Moods - record, delete, update a users mood
7. Moves - record a users moves list.
6. sleeps - sleep graph, record sleep, sleep list, specific sleep,
7. Timezone
8. Trends
9. Workouts, trends,

References:
https://jawbone.com/up/developer
https://jawbone.com/up/developer/structure
https://jawbone.com/auth/oauth2/auth

Tuesday, April 22, 2014

iOS Playing Streaming files

Almost urgently had to look into iOS feature for playing streaming file and running app in background and play the file. Below is some notes from it.

 Making the app to run in background to play the audio.

At a minimum
- UIBackgroundMode should be set to "App plays audio or streams audio/video using AirPlay"
- For basic playback set the audiosessioncategory to AVAudioSessionCategoryPlayback

Below code can be present in the app delegate didFinishLaunchingWithOptions method so that app gets the cycles to execute and play the music while in background.

AVAudioSession* audio = [[AVAudioSession alloc] init];
    [audio setCategory: AVAudioSessionCategoryPlayback error: nil];

    [audio setActive: YES error: nil];

A more hands on needs to be done for this part. In next blogs indeed.

This is very helpful link
http://www.sagorin.org/ios-playing-audio-in-background-audio/

Monday, April 21, 2014

iBeacon - Data Exchange after Ranging

iBeacons are transmit only devices and not the ones for exchanging data.

For exchanging data between two devices once the ranging is done, there are two approaches that can be followed

- Use CoreBluetooth framework
- Use Webservices and polling
- Using SIP services

The WebService way is a bit cumbersome as it involves the polling mechanism. Below is the procedure during the entire operation of the app.

- A detects that B is in range
- A writes to a webservice where B constantly reading.

This model involves B to constantly poll the service and it is bit overhead on network and devices.

Using the CoreBluetooth is a better approach as both the devices getting identified will have the Bluetooth on. However, only problem is that the type of data and the capability of device to support that profile may vary between device.

Using SIP is another option as the communication will look almost real time. When the beacon is in range, make a sip MESSAGE request and do the communication.

To get some more details on when the data operations are to be done. below are the three delegate methods iOS provides for this purpose

1. locationManager:didDetermineState:forRegion
2. locationManager:didEnterRegion:
3. locationManager:didExitRegion:

the locationManager:didDetermineState:forRegion is getting called always along with the #2,#3 methods. in this method, the below code can be used to determine whether the app entered into the region.

if(state == CLRegionStateInside)
    {
        notification.alertBody = NSLocalizedString(@"You're inside the region", @"");
    }
    else if(state == CLRegionStateOutside)
    {
        notification.alertBody = NSLocalizedString(@"You're outside the region", @"");

    }

The advantage of this method is that it get called in multiple situations:

1. This method gets called whenever didEnterRegion or didExitRegion is getting called. So it can be used in place of this
2. This method is getting called when requestStateForRegion method is called to get the state
3. If an iBeacons's property notifyEntryStateOnDisplay is set, then also this method is called even if the app is not running to notify that the region state is determined.



Sunday, April 20, 2014

Objective C pre-processor macros

Below is a list of pre-processor macros available in objective C.

__func__ => prints the current function signature
__LINE__ => prints the line number in the source code file
__FILE__ => path source to the source file
__PRETTY_FUNCTION__ is similar to __func__ but just that it is a gcc extension that prints the "pretty" name of the function including its signature. Used in C++.

When running the same in iOS code, it appears the __func__ and the __PRETTTY_FUNCTION__ give the same result

references:
https://developer.apple.com/library/ios/qa/qa1669/_index.html



Saturday, April 19, 2014

SIPp tool - installing on Windows

SIPp is a tool that can be used for testing the SIP scenarios by simulating it. The download page is at
http://sourceforge.net/projects/sipp/files/sipp/3.4/ as of this writing the latest version is 3.4

SIPp tool is mainly for Linux and Cygwin. Those who dont have a Linux machine, can install the Cygwin and configure the SIPp tool. SIPp on windows as per the sourceforge site, will work on WindowsXP and not on Windows 2000 due to IPV6 support.

There is a utility called SippGuiSetup.exe, but this is not really a GUI tool to simulate the test cases, but just a tool to prepare the call flows.

The detailed instructions for testing this is available at http://sipp.sourceforge.net/doc/reference.html
This notes are from my attempt to install on my Windows XP machine.

Step 1: Download Cygwin.
The download link is available at SIPp page which is http://win6.jp/Cygwin/
The version downloaded was, WpdPack_4_1_2

- Downloaded the zip file at this location and it contained bin, usr, lib files inside
- Download the WinPcap developer pack and copy to c:\cygwin\lib\WpdPack. The instructions page asked to rename the pthread.h file inside the c:\cygwin\lib\WpdPack\include , but this file was not available in the cygwin that i downloaded.

It appears that the Cygwin installation is not correct and it was not able to get to the Cygwin command line.

Tried searching again and found a link to directly install the Cygwin as an exe. The link is available here.

The cygwin installation was successful, and tried to execute the cygwin using the command prompt as well as given in the reference. However, this was getting a failure.

This needs to be tried again!

references:

http://sipp.sourceforge.net/
http://sipp.sourceforge.net/doc/reference.html

Thursday, April 17, 2014

Sip Stack - REGISTER analysis

SalOp is the main structure passed around in various classes. When linphone_proxy_config_register is called, it is creating a new SalOp using sal_op_new function and the SalOp's userdata pointer is set to the LPConfig object

The refresher, transaction is two main portions of the core. For every request, a transaction is created and a refresher is created with this transaction. For specific functionalities, there are specific c files. For example, for registration, the file is sal_op_register.c, this file is mainly for doing the register related header addition, set from, to, contact, route headers, builds the request using sal_op_build_request, and finally calls the sal_op_impl.c file to send and create the request. sal_op_impl.c calls the transaction api to create a transaction and it in turn creates a refresher as well. When it asks the sal_op_impl.c to create a transaction and register, it sends a function pointer as the listener inorder to get the call backs.

The sal_op_impl.c also sets a default retry timer of 1 minute that kicks in when the request is not able to be sent out. also, it has a manual mode refresher. This is mainly to decide whether the refresh should be done by the library or by the app when the expiration of the refresher timer happens.

Below is the websequence diagram notes for the REGISTER sending part

lpcore -> proxy.c : lp_proxy_config_register(true)
proxy.c -> sal_op_registration.c : sal_register
sal_op_registration.c -> sal_op_impl.c : sal_op_send_and_create_refresher
sal_op_impl.c -> sal_op_impl.c : sal_op_send_request_with_expires
sal_op_impl.c -> transaction.c : belle_sip_client_transaction_create_refresher
transaction.c -> refresher.c : belle_sip_refresher_new

In another Blog, the details of processing of the incoming SIP message will be analyzed


Wednesday, April 16, 2014

Unit testing iOS code - SenTesting framework

Apple gives definition of unit testing as a way to ensure that the code you write adhere to the design specifications and it keep adhering to the specifications as you modify it. To me, it is almost the same and also making sure the code is without lot of bugs especially around the area those are rarely tested or executed in real world.

Xcode gives a way to include Unit test bundles. These bundles contain methods that exercise the code in a library or app to perform unit testing.

There are main three portions to it.

1. Setting up unit testing in a project
2. Writing test case methods
3. Running unit tests

Setting up the unit testing is pretty straight forward. on the project window add a new target and select the type as Other -> Cocoa Touch Unit Testing Bundle. Give the target name. In the new versions of XCode, am using the XCode 5.0 it asks for the Type of the Unit testing. The drop down has two options 1, OCUnit (Xcode 4 compatible) 2, XCTest

Selecting the OCUnit makes the SenTestingKit framework a required library to be added. This time selected the OCUnit as the XCTests is comparatively newer approach that also integrates with the Continuous Integration feature available in XCode 5.0.

Adding a new Unit Testing Target includes a set of source files which is containing one function testExample and other two life cycle functions setUp, tearDown.

Below are the instructions before running the tests which i had to do to get this working.

- In the build settings pane, search for bundle loader and test host and test host. If these are highlighted, which means these are having some values, then delete them so that they become unhighlighted. from Products -> Run, run the tests.  This was going through the setUp , testExample, tearDown methods in order and since the testExample had statement STFail, the test was declared to be failure.

Next review of this framework, i think mainly the below will be interesting

- How to write more test methods
- how to do testing that involves server responses
- How to do testing of screen flow
- How to run some test at some point of execution in the app midway.

This below article gives Good explanation of the entire setup
https://developer.apple.com/legacy/library/documentation/DeveloperTools/Conceptual/UnitTesting/02-Setting_Up_Unit_Tests_in_a_Project/setting_up.html#//apple_ref/doc/uid/TP40002143-CH3-SW1



Tuesday, April 15, 2014

iBeacon Hands On - Transmitter & Scanner Part

Finally decided to implement the details acquired into an app.

There are two parts for this app. One, Beacon Tranmittor and next part is Beacon Monitor.

- Created a Single View application
- included CoreLocation, CoreBluetooth frameworks to it.
- Created a class BeaconTransmitter
- Created CLBeaconRegion object to create the beacon region for transmission
- Created a NSDictionary to hold the peripheral properties of this beacon
- Created a CBPeripheralManager instance to create get the delegates for peripheral start and stop. This is used for start and stop of advertising respectively.

Implemented the CBPeripheralManagerDelegate to get the peripheral updates. in the peripheral update when the event is CBPeripheralManagerStatePoweredOn, startAdvertising the beacon using peripheral manager startAdvertising api by passing the beacon properties dictionary.  Similarly, when the state is powered off, we should stop the advertising.


For the Beacon Monitoring part, the main two classes required are

. CLLocationManager
- CLBeaconRegion

first need to create an instance of CLLocationManager and set the delegate and override the didEnterRegion and didExitRegion methods mainly. We also need to initiate the CLBeaconRegion object and give the uuid as the known uuid of the beacon . say for e,g. the uuid given in the above trasmitting part. also the same identifier can be given as well. to start monitoring for region, core location manager instance created has a method startMonitoringForRegion. When the didEnterRegion is called back, the code can search for ranging the beacon with the given identifiers specificatlly using startRangingBeaconsInRegion. Similarly when the didExitRegion is called back, code can stop ranging the beacons. When the specific beacon is ranged, the didRangeBeacons method will be called back. We get a set of beacons in this call back and one can decide based on number of factors such as proximity, rssi strength etc.

Below is my observation on the whole application

- If the transmitter is a phone, when the screen locks up, the device which is monitoring for this transmitter receives didExitRegion callback. This makes the app to be available always in foreground. This is kind of a restriction. But assuming in the realworld, it may be some other device that is acting as a transmitter

- When the call back didRangeBeacon comes into the app, it keeps coming. But if kill the app and launch again, even though other transmitter is still transmitting, the didRangeBeacon doesnt come to the app.





Sunday, April 13, 2014

SOAP frameworks for iOS

gSoap is a SOAP framework built on C++. This is available on multiple platforms such as Windows, MAC, WINCE, Symbian, Palm OS. This framework is open source for non commercial use. This is licensed under GPLv2. This toolkit follows WS-I Basic Profile 1.0a, 1.1, 1.2 recommendations. 

This framework supports SOAP 1.1/1.2, WSDL 1.1/1.2, UDDI v2.0 WS Policy 1.2/1.5, WS Security Policy 1.5, WS-Reliable Messaging, WS-Addressing, Supports XML schema primitive XSD types, simple types, complex types, extension, restriction elements, attributes, elements/attribute references etc. 

A good amount of documentation on this can be found at http://www.cs.fsu.edu/~engelen/soap.html

Other frameworks are: 

http://code.google.com/p/wsdl2objc -
http://sudzc.com 
http://www.cs.fsu.edu/~engelen/soap.html -

MotionManager, Augmented Reality framework a quick look


Magneto meter.
CMMotoionManager : is the iOS framework to get the motion services provided by the iOS. This services provides app with accelerometer data, rotation-rate data, magnatometer data and other device motion data such as attitude.  The framework supports accessing both raw and processed accelerometer data using block based interfaces. For devices with built in gyro scope, one can retrieve the gyro data as well and process data reflecting attittude and rotation rates of device. One can use both the accelerometer and gyro based data for games or other apps that use motion as input or as a way to enhance overall user experience.

references: https://www.inkling.com/read/learning-ios-programming-alasdair-allan-2nd/chapter-9/the-core-motion-framework

Augmented Reality Framework : 
Augmented reality is a cool and popular technique where you view the world through device you like, say camera of an iPhone or google glass and overlay extra info about those places on top of the real world view.  

The question of why we need this framework irrespective of Map frameworks, is that when we need to find where to place the overlay on the screen for a POI. for e.g. If we have a POI on the north side of you and the device is pointing to the north east, the question is where to show the POI. towards the left or to the center. It all depends on the current position of the device. If the device is sligthly towards the ground, the POI should be shown at the top. If it is pointing to the south, the POI should not be shown at all. The ARKit uses the device's gyroscope and the compass to find out where the device is pointing and the degree of tilt. Using this info it decides where and whether the POI should be shown. 

references: http://www.raywenderlich.com/42266/augmented-reality-ios-tutorial-location-based






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"