Wednesday, May 20, 2015

Swift: URL response caching using NSURLCache.

Download XCode project

//Create request with caching policy
let request = NSURLRequest(URL: url, cachePolicy: NSURLRequestCachePolicy.ReturnCacheDataElseLoad, timeoutInterval: 60)
//Get cache response using request object
let cacheResponse = NSURLCache.sharedURLCache().cachedResponseForRequest(request)
//check if cached response is available if nil then hit url for data
if cacheResponse == nil {

            //default configuration
            let config = NSURLSessionConfiguration.defaultSessionConfiguration()

            //Enable url cache in session configuration and assign capacity
            config.URLCache = NSURLCache.sharedURLCache()
            config.URLCache = NSURLCache(memoryCapacity: 51200, diskCapacity: 10000, diskPath: "urlCache")
            //create session with configration
            let session = NSURLSession(configuration: config, delegate: self, delegateQueue: nil)
            //create data task to download data and having completion handler
            let task = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in
                //below two lines will cache the data, request object as key
                let cacheResponse = NSCachedURLResponse(response: response, data: data)
                NSURLCache.sharedURLCache().storeCachedResponse(cacheResponse, forRequest: request)
        } else {
            //if cache response is not nil then print
            let string = NSString(data: cacheResponse!.data, encoding: NSUTF8StringEncoding)


Saturday, April 25, 2015

Android device screen cast or screen recording using command prompt in windows machine.

Follow below steps:

1. Open command prompt (cmd) in windows (click window+R, type cmd in it and press enter)

2. Go to adb (android debug bridge) platform tools, it will be in your android sdk folder:
     Example - C:\Users\abc\AppData\Local\Android\sdk\platform-tools

3. Connect your android phone

4. Run command to record: adb shell screenrecord --verbose ./sdcard/record-video.mp4

5. To stop recording, press: Ctrl+C

Tuesday, September 9, 2014

Extract Source Code from Android APK file

Procedure for decoding .apk files, step-by-step method:
Step 1:
Make a new folder and put .apk file in it (which you want to decode). Now rename the extension of this .apk file to .zip (eg.: rename from filename.apk to and save it. Now you get classes.dex files, etc. At this stage you are able to see drawable but not xml and java files, so continue.
Step 2:
Now extract this zip apk file in the same folder (or NEW FOLDER). Now download dex2jar from this link and extract it to the same folder (or NEW FOLDER). Move the classes.dex file into the dex2jar folder. Now open command prompt and change directory to that folder (or NEW FOLDER). Then write dex2jar classes.dex and press enter. Now you get classes.dex.dex2jar file in the same folder. Then download java decompiler from and now double click on jd-gui and click on open file. Then open classes.dex.dex2jar file from that folder. Now you get class files and save all these class files (click on file then click "save all sources" in jd-gui) by src name. At this stage you get java source but the xml files are still unreadable, so continue.
Step 3:
Now open another new folder and put these files
1.      put .apk file which you want to decode
2.      download apktool v1.x AND apktool install window (both can be downloaded at the same location) and put in the same folder
3.      download framework-res.apk file and put in the same folder (Not all apk file need framework-res.apk file)
4.      Open a command window
5.      Navigate to the root directory of APKtool and type the following command: apktool if framework-res.apk (Try below trobleshooting if not working)
6.      apktool d "fname".apk ("fname" denotes filename which you want to decode)
now you get a file folder in that folder and now you can easily read xml files also.
Step 4:
It's not any step just copy contents of both folder(in this case both new folder)to the single one
and now enjoy with source code...

1. From Step 3-->point 5 --> apktool is not recognize as an internal command.
Solution: This may be a PATH problem,do this:
ApkToolPath is the directory where apktool is.
BTW, u need to download 2 files: apktool-install-windows-r05-ibot.tar.bz2 and apktool1.5.2.tar.bz2. extract both and put aapt.exe apktoo.bat apktool.jar together.

Wednesday, December 11, 2013

Thursday, April 18, 2013

Implement Auto Suggestions in iOS/iPhone/iPad

A tutorial to implement auto suggestion while typing in iPhone. Below is the link to download a source code. Let me know for any query.

Download Source Code : AutoSuggestion_iOS