Thursday, 6 September 2018

Record iOS App Flow on simulator apple script application

To show our App UI behaviour we generally use: 
1) App screen shots or
2) App flow recording.

App screenshot is easy to take as iPhone Simulator offer a simple way to capture a screenshot under the File tab (File -> Screen Shot) or cmnd+S.

To record app flow we generally use the QuickTime Player, select the area of simulator and start screens recording. For me, sometime it's hectic because it blocks that area of the screen to use for the system. If we use that area for any other window, that window will also record in recording, and we have to record our flow again. Don't you think it irritating?

So, Is it possible to record the simulator app flow without block of screen area? Yes, we can do that using a command line tool.

Screen simctl is a powerful command to control simulator using command line. So lets quickly record our app flow in the simulator.

open a terminal and write the following command:





Example:







It will start recording your simulator, now use your app so that flow can record.

Once you are done with app flow covered, press ctrl+C to stop recording. You recorded file will be saved at your defined path "/Users/username/Public/myAppFlow.mov".

Hope you enjoy it.

But, I am still not happy with it. The reason I am a lazy person, so I found it still painful to open terminal every time (if it's not open and open a new window or tab if it opened) and type the command and record it and then go to finder and see where is my recoding. 
In this case I mostly forgot to close the terminal after use it (You know I am a lazy person :))

So I like to automate or want an application that we can put in our dock and use it with one click for recording. What our app should do, let's create the use case and flow for that:

1: App should check if your simulator is open or not. 
2: If not opened, asked you to open the simulator first.
3: If the simulator is open, check for terminal is open or not 
4: If the terminal is not open, open new terminal window 
5: If the terminal is open already, open new tab in a terminal window so that previous running work does not effected.
6: Run the cmd line tool for video record.
7: User use app so it will record. Once you finish with app usage to record, There should be button to finish recording.
8: Close the terminal if we it was not previously launched.
9: Close the tab of terminal that we open for our command run.
10: Open the video recorded path in finder with the Default Quicktime player to view what we recorded.


To create such app for MacBook, Apple provides serious way. You can use Mac App using Xcode, can create Automator workflow or you can write and apple script application. I would prefer apple script for this type of App. Here is the Code for above mentioned use cases covered script. You can find code here on github project Simulator_record_script.


If you, new to Apple script, you can get some help with my previous Tutorial on apple script. 

So now, we have done with the Apple script code. Lets Export it as an application.
You can download it from here . 

It will show you warning that it harm your computer as it a script application. So you can goto my github project  and download the code source file open it in apple script editor. Once you feel it not have any privacy breaking code you can also export it as application and use it.

Put it in your dock and use for easy video recording of app flow in the simulator for your usage (client demo, GIF from video for GitHub repo, bug discussion of UI flow etc.)

Hope you enjoy it and it helps you in your work.

Tuesday, 24 October 2017

iOS 11/12 Debugging with Xcode 8/9 without upgrading to Xcode 9/10

Note: Download  iOS 12 support file from here and follow the same steps to achieve iOS 12 Debugging on Xcode 9.

Hello Everyone, as we all know new version of iOS (iOS 11) and Xcode (Xcode 9) launched by apple. To run on iOS 11, we need to upgrade our code with Xcode 9, but many of us do not want to upgrade our code to new Xcode 9 due to reasons like:

# Working on swift version below 3.0 and Xcode 9 will work only above 3.0
# Due to some compile time errors while running on Xcode 9.
# Need more time to fix build issue and conversion issue to run our code on Xcode 9.

Don't worry, there is another way to debug iOS 11 without upgrading to Xcode 9. You can use older Xcode 8 to debug iOS 11 device. You just need to follow the below steps:

Step 1: Download Xcode 9 (https://developer.apple.com/download/) & Install it. Do not replace the Xcode 8 while install, chose keep both rather than replacing the previous one.


Step 2: Find the installed Xcode 9.app file in application folder, and right click to icon and click Show Package Content.






Step 3: Go to Contents > Developer > Platforms > iPhoneOS.platform > DeviceSupport
or use the finder goto folder with path /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/
Here you will see iOS 11 Support file folder, copy it.







 Or you can download the support files from here iOS 11 Device support file

Step 4: Now, In Application folder, Right click on  Xcode 8 and click on show content packages.



Step 5: Go to Contents > Developer > Platforms > iPhoneOS.platform > DeviceSupport
or use the finder goto folder with path /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/
Paste the Copied iOS 11 Support files folder here.




Once you paste it , confirm you have the iOS 11 files in device support of XCode 8.






Step 6: Restart the Xcode 8 and quite the Xcode 9,  now you can run your code on iOS 11 with Xcode 8.

Wednesday, 27 September 2017

iOS Layered Architecture


Hello Everyone, Hope you are all doing Good. I was planning to post some helpful swift, playground tutorials from long time. Before going deep in swift and swift playground, lets quick overview how our code communicate to iOS and hardwares. Lets knew about iOS Layered Architecture and iOS App lifecycle(may be will cover be in Next Blog).

Understanding a little about the technologies and tools contained in the SDK can help you make better choices about how to design and implement your apps.

Architecture of iOS is little bit same as MAC layered architecture but in iOS Apple replaced by MAC COCOA By COCOA Touch (Figure-1). Each of these layers is made up of a variety of different frameworks that can be used and incorporated into your applications.





At the upper most level iOS work as an mediator between the underlying hardware and the apps we create. Out app do not communicate to the underlying hardware directly.

Apps talk with the hardware through a collection of well defined system interfaces. These interfaces make it simple to write apps that work constantly on devices having various hardware abilities.

Lower level  layers: They gives the basic services which all application relies on
Higher level  layer: They gives sophisticated graphics and interface related services.

Apple provides most of its system interfaces in special packages called frameworks.
So what is this framework actually contains? - Framework is a directory that holds a dynamic shared library that is .a files, related resources like as header files, images, and helper apps required to support that library.

Every layer have a set of Framework which the developer use to construct the applications. Every version of iOS contains a set of frameworks. We can create our framework also and use them across multiple applications. But lets knew only about iOS framework now, we will learn creating our framework later :)

Lets know a little bit about each layer and see what frameworks it contains.

Cocoa Touch Layer


The Cocoa Touch layer contains key frameworks for building iOS apps. These frameworks define the appearance of your app. They also provide the basic app infrastructure and support for key technologies such as multitasking, touch-based input, push notifications, and many high-level system services. When designing our apps, we should investigate the technologies in this layer first to see if they meet our needs.

Frameworks contains: 

  • EventKitUI.framework - provides view controllers for presenting the standard system interfaces for viewing and editing calendar-related events.
  • GameKit Framework – implements support for Game Center which allows users share their game related information online
  • iAd Framework – allows you deliver banner-based advertisements from your app.
  • MapKit Framework – gives a scrollable map that you can include into your user interface of app.
  • PushKit Framework – provides registration support for VoIP apps.
  • Tweeter Framework – supports a UI for generating tweets and support for access the Twitter Services.
  • UIKit Framework – gives vital infrastructure for applying graphical, event-driven apps in iOS. Some of the Important functions of UI Kit framework:
    • Basic app management and infrastructure.
    • Multitasking support.
    • User interface management
    • Support for using custom input views that behave like the system keyboard
    • Support for sharing content through email, Twitter, Facebook, and other services
    • Support for Touch and Motion event.
    • Cut, copy and paste support and many more.
  • Newly introduce Framework
    • Message UI Framework.
    • AddressBookUI framework
    • Notification Center Framework


Media Layer

It is the second layer from the top of the stack. It provides the iPhone OS with audio, video, animation and graphics capabilities. As with the other layers of the iPhone OS stack, the Media layer comprises a number of frameworks that can be utilised when developing iPhone apps.

Frameworks contains  We can divide it into three parts:

  1. Graphics Framework:
    • UIKit Graphics – It describes high level support for designing images and also used for animating the content of your views.
    • Core Graphics framework – It is the native drawing engine for iOS apps and gives support for custom 2D vector and image based rendering.
    • Core Animation – It is an initial technology that optimises the animation experience of your apps.
    • Core Images – gives advanced support for controlling video and motionless images in a nondestructive way
    • OpenGl ES and GLKit – manages advanced 2D and 3D rendering by hardware accelerated interfaces
    • Metal – It permits very high performance for your sophisticated graphics rendering and computation works. It offers very low overhead access to the A7 GPU.                                                                                                                                                                                                                           
  2. Audio Framework:  
    • Media Player Framework – It is a high level framework which gives simple use to a user’s iTunes library and support for playing playlists.
    • AV Foundation – It is an Objective C interface for handling the recording and playback of audio and video.
    • OpenAL – is an industry standard technology for providing audio.                                                                                                                                                                                          
  3. Video Framework

    • AV Kit – framework gives a collection of easy to use interfaces for presenting video.
    • AV Foundation – gives advanced video playback and recording capability.
    • Core Media – framework describes the low level interfaces and data types for operating media.



Core Services Layer


It is the third layer from the top of the stack. The iPhone Core Services layer provides much of the foundation on which the above layers are built. It provide Peer-to-Peer Services, iCloud Storage, Block Objects, Data Protection, File-Sharing Support, Grand Central Dispatch, In-App Purchase, SQLite, XML Support features.

Frameworks contains:


  • EventKit Framework - The EventKit framework (EventKit.framework) provides an interface for accessing calendar events on a user’s device.
  • Accounts Framework - The Accounts framework (Accounts.framework) provides a single sign-on model for certain user accounts.
  • Address book framework – Gives programmatic access to a contacts database of user.
  • Cloud Kit framework – Gives a medium for moving data between your app and iCloud.
  • Core data Framework – Technology for managing the data model of a Model View Controller app.
  • Core Foundation framework – Interfaces that gives fundamental data management and service features for iOS apps.
  • Core Location framework – Gives location and heading information to apps.
  • Core Motion Framework – Access all motion based data available on a device. Using this core motion framework Accelerometer based information can be accessed.
  • Foundation Framework – Objective C covering too many of the features found in the Core Foundation framework
  • HealthKit framework – New framework for handling health-related information of user
  • HomeKit framework – New framework for talking with and controlling connected devices in a user’s home.
  • Social framework – Simple interface for accessing the user’s social media accounts.
  • StoreKit framework – Gives support for the buying of content and services from inside your iOS apps, a feature known asIn-App Purchase.
  • CFNetwork
  • System Configuration Framework


Core OS Layer:


This is the bottom layer of the hierarchy and is responsible for the foundation of the operating system which the other layers sit on top of. This important layer responsible to managing memory—allocating and releasing memory once the application has finished with it, taking care of file system tasks, handling networking, and other operating system tasks. It also interacts directly with the hardware.

Frameworks contains:


  • Core Bluetooth Framework - The Core Bluetooth framework (CoreBluetooth.framework) allows developers to interact specifically with Bluetooth low energy (LE) accessories. 
  • Accelerate Framework - The Accelerate framework (Accelerate.framework) contains interfaces for performing digital signal processing (DSP), linear algebra, and image-processing calculations.
  • External Accessory Framework -The External Accessory framework (ExternalAccessory.framework) provides support for communicating with hardware accessories attached to an iOS-based device.
  • Security Services framework.
  • Local Authentication framework.
  • 64-Bit support from IOS7 supports the 64 bit app development and enables the application to run faster.

Below Core OS layer hardware layer exists. Hardware devices are managed by iPhone OS and provides the technologies needed for implementing native applications on the phone.

In next part we will cover App Life cycle using Process, Main,AppDelegate and Window interface.




Wednesday, 28 October 2015

UIImage Category( Resize+RoundCourner+Alpha) Swift version

For iOS developer, Resizing images, cropping them to a specific thumbnail size, applying rounded corners is extremely easy with Trevor Harmon’s Image categories UIImage Category. These category helped many developers to finish image implementation quickly and very easily in their projects.

After apple announcement, "Swift will become a successor of objective -C", mostly iOS app developer switching their development in swift language. As Trevor Harmon’s Image categories are written in Objective-C, so developer chose bridging concept to use these category features in the swift code.

Nowadays people bypass a bridging headache as they like to complete their whole project in Swift. It will be helpful for them if they found the category in swift so that they can easily use it and finish their projects within deadline with a smiling face. 

I have created a swift version of Trevor Harmon’s Image categories found in a Blog.  Also, I have added some new methods and extra features. Here is the link of Github of these category files.

https://github.com/Rupesh17/UIImage-Category-Swift

You can download them, use them directly without bridging headache like Objective-C version.

Modification or suggestion will be helpful to make it best.  In case, of any question or suggestion feel free to ask. Also, If you want any other helpful objective -C code in swift, let me know.




Tuesday, 29 September 2015

App Transport Security (ATS) and iOS 9 HTTP Connection error "The operation couldn’t be completed"

In 2015, With the launch of iOS 9 and OSX  El Capitan apple disabled all unsecured HTTP traffic from iOS apps and comes with new privacy feature called App Transport Security (ATS) to enforce best practices in secure connections between an app and its back end.

All iOS 9 devices running apps built with Xcode 7 that don’t disable ATS will be affected by this change and if app try to make HTTP requests with ATS enabled (iOS 9 and above), we will see the errors like this:

Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server." UserInfo=0x12ed5bad0 {NSUnderlyingError=0x12ee495b0 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1004.)"

OR

NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)

Before finding the solution to resolve this error we should know about ATS and why apple recommend this .

What is ATS and Why Apple pushing it as default from iOS 9?

According to apple “ App Transport Security (ATS) lets an app add a declaration to its Info.plist file that specifies the domains with which it needs secure communication. ATS prevents accidental disclosure, provides secure default behavior, and is easy to adopt. You should adopt ATS as soon as possible, regardless of whether you’re creating a new app or updating an existing one.

If you’re developing a new app, you should use HTTPS exclusively. If you have an existing app, you should use HTTPS as much as you can right now, and create a plan for migrating the rest of your app as soon as possible.“

Simply, App Transport Security is a feature that improves the security of connections between an app and web services. The feature consists of default connection requirements that conform to best practices for secure connections.

The reason why Apple is pushing so aggressively to force secure connections is because it’s the right thing to do. Protecting personal data from being compromised over insecure wireless connections, among other things, is great for users.


Requirement to adopt ATS :

App Transport Security is enabled by default when using NSURLSession, NSURLConnection, or CFURL in iOS 9 or OS X El Capitan.

App Transport Security requirements:

 * The server must support at least Transport Layer Security (TLS) protocol version 1.2.

 * Connection ciphers are limited to those that provide forward secrecy (see the list of ciphers below.)

 * Certificates must be signed using a SHA256 or greater signature hash algorithm, with either a 2048-bit or greater RSA key or a 256-bit or greater Elliptic-Curve (ECC) key.Invalid certificates result in a hard failure and no connection.


If your application attempts to connect to any HTTP server that doesn’t support the latest SSL technology (TLSv1.2), your connections will fail with an error like this:

Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server." UserInfo=0x12ed5bad0 {NSUnderlyingError=0x12ee495b0 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1004.)"

OR

App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.


How to Bypass App Transport Security:

ATS is good for you and your users and you shouldn’t disable it, but there are the way for developers to override this default behavior and turn off transport security as per the app requirement. To disable ATS you need to Open Info.plist, and add the following lines:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>


Your info.plist must be look like this.




Per-Domain Exceptions:

You can opt-out of ATS for certain URLs in your Info.plist by using NSExceptionDomains. Within the NSExceptionDomains dictionary you can explicitly define URLs that you need exceptions for with ATS.

Add this code to your info.plist source file.


<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>server1.com</key>
            <dict>
                <!--Include to allow subdomains-->
                <key>NSIncludesSubdomains</key>
                <true/>
                <!--Include to allow HTTP requests-->
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <!--Include to specify minimum TLS version-->
                <key>NSExceptionMinimumTLSVersion</key>
                <string>TLSv1.1</string>
            </dict>
            <key>server2.com</key>
            <dict>
                <!--Include domain support forward secrecy using ciphers-->
                <key>NSExceptionRequiresForwardSecrecy</key>
                <true/>
                <!--Include to allow HTTP requests-->
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <false/>
            </dict>
        </dict>
    </dict>

Your structured info.plist source file looks like this.



And your info.plist looks like this :




Now, You can see ATS is good for app developers and app users as it improves the security of connections between an app and web services, but you can override it.