Monday, March 6, 2017

iOS how to know if Accessiblity Voiceover is running on device

The methods below will give info about whether accessibility is running

func UIAccessibilityIsVoiceOverRunning() -> Bool

You can use this function to customize your application’s UI specifically for VoiceOver users. For example, you might want UI elements that usually disappear quickly to persist onscreen for VoiceOver users. Note that you can also listen for the UIAccessibilityVoiceOverStatusChanged notification to find out when VoiceOver starts and stops, which is below.

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(voiceOverStatusChanged)
                                             name:UIAccessibilityVoiceOverStatusChanged
                                           object:nil];


- (void)voiceOverStatusChanged
{
    if(!UIAccessibilityIsVoiceOverRunning())
    {
        //do your changes
    }
}

On Android below API will help on this

AccessibilityManager am = (AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE);
boolean isAccessibilityEnabled = am.isEnabled();
boolean isExploreByTouchEnabled = am.isTouchExplorationEnabled();

references:
https://developer.apple.com/reference/uikit/1615187-uiaccessibilityisvoiceoverrunnin


What is difference between .cc & .cpp extension?

Historically, the suffix for a C++ source file was .C. This caused a few problems the first time C++ was ported to a system where case wasn't significant in the filename.

Different users adopted different solutions: .cc, .cpp, .cxx and possibly others. Today, outside of the Unix world, it's mostly .cpp. Unix seems to use .cc more often.

For headers, the situation is even more confusing: for whatever reasons, the earliest C++ authors decided not to distinguish between headers for C and for C++, and used .h.

This doesn't cause any problems if there is no C in the project, but when you start having to deal with both, it's usually a good idea to distinguish between the headers which can be used in C (.h) and those which cannot (.hh or .hpp).

In addition, in C++, a lot of users (including myself) prefer keeping the template sources and the inline functions in a separate file. Which, while strictly speaking a header file, tends to get yet another set of conventions (.inl, .tcc and probably a lot of others).

In the case of headers it makes absolutely no difference to the compiler.

In the case of source files different endings will cause the compiler to assume a different language. But this can normally be overridden, and I used .cc with VC++ long before VC++ recognized it as C++.

Sunday, March 5, 2017

What is GN Build System? - Basics

GN is a meta-build system that generates NinjaBuild files so that you can build Chromium with Ninja

Adding a build file
Create a tools/gn/tutorial/BUILD.gn file and enter the following:
    
    executable("hello_world") {
        sources = [
                   "hello_world.cc",
                   ]
    }

There should already be a hello_world.cc file in that directory, containing what you expect. That's it! Now we just need to tell the build about this file. Open the BUILD.gn file in the root directory and add the label of this target to the dependencies of one of the root groups (a “group” target is a meta-target that is just a collection of other targets):

group("root") {
        deps = [
                ...
                "//url",
                "//tools/gn/tutorial:hello_world",
                ]
    }

You can see the label of your target is “//” (indicating the source root), followed by the directory name, a colon, and the target name.

Testing your addition
From the command line in the source root directory:

gn gen out/Default
ninja -C out/Default hello_world
out/Default/hello_world

GN encourages target names for static libraries that aren't globally unique. To build one of these, you can pass the label with no leading “//” to ninja:

ninja -C out/Default tools/gn/tutorial:hello_world

Declaring dependencies
Let's make a static library that has a function to say hello to random people. There is a source file hello.cc in that directory which has a function to do this. Open the tools/gn/tutorial/BUILD.gn file and add the static library to the bottom of the existing file:

static_library("hello") {
        sources = [
                   "hello.cc",
                   ]
    }

Now let's add an executable that depends on this library:

executable("say_hello") {
        sources = [
                   "say_hello.cc",
                   ]
        deps = [
                ":hello",
                ]
    }

This executable includes one source file and depends on the previous static library. The static library is referenced by its label in the deps. You could have used the full label //tools/gn/tutorial:hello but if you're referencing a target in the same build file, you can use the shortcut :hello.

Test the static library version

ninja -C out/Default say_hello
    out/Default/say_hello


Compiler settings
Our hello library has a new feature, the ability to say hello to two people at once. This feature is controlled by defining TWO_PEOPLE. We can add defines like so:

static_library("hello") {
        sources = [
                   "hello.cc",
                   ]
        defines = [
                   "TWO_PEOPLE",
                   ]
    }

Putting settings in a config

However, users of the library also need to know about this define, and putting it in the static library target defines it only for the files there. If somebody else includes hello.h, they won't see the new definition. To see the new definition, everybody will have to define TWO_PEOPLE.
    
    GN has a concept called a “config” which encapsulates settings. Let's create one that defines our preprocessor define:

config("hello_config") {
        defines = [
                   "TWO_PEOPLE",
                   ]
    }

To apply these settings to your target, you only need to add the config's label to the list of configs in the target:

static_library("hello") {
        ...
        configs += [
                    ":hello_config",
                    ]
    }

Note that you need “+=” here instead of “=” since the build configuration has a default set of configs applied to each target that set up the default build stuff. You want to add to this list rather than overwrite it. To see the default configs, you can use the print function in the build file or the desc command-line subcommand (see below for examples of both).

Dependent configs

This nicely encapsulates our settings, but still requires everybody that uses our library to set the config on themselves. It would be nice if everybody that depends on our hello library can get this automatically. Change your library definition to:

static_library("hello") {
        sources = [
                   "hello.cc",
                   ]
        all_dependent_configs = [
                                 ":hello_config"
                                 ]
    }

Add a new build argument
You declare which arguments you accept and specify default values via declare_args.

declare_args() {
        enable_teleporter = true
        enable_doom_melon = false
    }

Don‘t know what’s going on?

You can run GN in verbose mode to see lots of messages about what it's doing. Use -v for this.

Print debugging

There is a print command which just writes to stdout:

static_library("hello") {
    ...
    print(configs)
}

The “desc” command

You can run gn desc to get information about a given target:

gn desc out/Default //tools/gn/tutorial:say_hello

will print out lots of exciting information. You can also print just one section. Lets say you wanted to know where your TWO_PEOPLE define came from on the say_hello target:

> gn desc out/Default //tools/gn/tutorial:say_hello defines --blame
...lots of other stuff omitted...
From //tools/gn/tutorial:hello_config
(Added by //tools/gn/tutorial/BUILD.gn:12)
 TWO_PEOPLE

Performance
You can see what took a long time by running it with the --time command line flag. This will output a summary of timings for various things.

You can also make a trace of how the build files were executed:

gn --tracelog=mylog.trace


references:
https://chromium.googlesource.com/chromium/src/tools/gn/
https://chromium.googlesource.com/chromium/src/tools/gn/+/HEAD/docs/quick_start.md#Adding-a-build-file

Friday, March 3, 2017

ATS requirement from Apple

In summary, below is what we need to do in the apps

1. Make every URLs to https
2. Ensure the TLS version is TLS1.2.
3. Have the certificate used in the server to client communication is trusted.

How do we detect if a URL is ATS compliant?

The nscurl tool on OS X El Capitan supports diagnosing ATS secure connections.

For example, /usr/bin/nscurl --ats-diagnostics https://www.example.com will display ATS connection information for www.example.com. Run /usr/bin/nscurl -h for more information.

This tools prints PASS / FAIL information. Ensure PASS results for test with diagnose dictionary with NO exceptions specified.

To view the certificate info of a particular Domain or test out the connection, TLS tool will be a good utility.
https://developer.apple.com/library/content/samplecode/sc1236/Introduction/Intro.html#//apple_ref/doc/uid/DTS40014927-Intro-DontLinkElementID_2


Does it affect Socket communication?

Below is the answer from Apple staff (https://forums.developer.apple.com/thread/48979)

Right now ATS is only enforced by our high-level APIs (NSURLSession, NSURLConnection, and anything layered on top of those), and there’s been no announcements about that changing.
Keep in mind, however, that ATS’s enhanced security requirements are not arbitrary; they are defined to give your users a good level of security on an increasingly hostile Internet.  As such, your app should aim to comply with these requirements even if ATS is not actively enforcing them.



https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW59
(Section NSAppTransportSecurity) 

Thursday, March 2, 2017

Swift how to have a Textfield that is having only bottom border





Below can be written on file say for e.g. UITextFieldExtension

extension UITextField{

func useUnderline() {

self.borderStyle = UITextBorderStyle.none

self.backgroundColor = UIColor.clear

let width = 1.0

let borderLine = UIView()

borderLine.frame = CGRect(x: 0, y: Double(self.frame.height) - width, width: Double(self.frame.width), height: width)

borderLine.backgroundColor = UIColor.lightGray

self.addSubview(borderLine)

}

at the time of calling , it can be called like below


 tfSample.useUnderline()

references:

Installing Git LFS

Git Large File Storage (LFS) replaces large files such as audio samples, videos, datasets, and graphics with text pointers inside Git, while storing the file contents on a remote server like GitHub.com or GitHub Enterprise.


Steps are simple 

1) Download and install the Git command line extension. You only have to set up Git LFS once.

git lfs install

2) Select the file types you'd like Git LFS to manage (or directly edit your .gitattributes). You can configure additional file extensions at anytime.

git lfs track "*.framework"

3) Make sure .gitattributes is tracked

git add .gitattributes

4) There is no step three. Just commit and push to GitHub as you normally would.

git add file.psd
git commit -m "Add framework file"
git push origin master

One can also do a command line + Source tree approach, in which case, before pushing to server,  if open the project in Source Tree, below will be asked to the user. 



references:

Wednesday, March 1, 2017

Extensions in Swift 3.0

Extensions add new functionality to an existing class, structure, enumeration, or protocol type. This includes the ability to extend types for which you do not have access to the original source code (known as retroactive modeling). Extensions are similar to categories in Objective-C. (Unlike Objective-C categories, Swift extensions do not have names.)

Below is what we can do with Extensions in Swift 

Add computed instance properties and computed type properties
Define instance methods and type methods
Provide new initializers
Define subscripts
Define and use new nested types
Make an existing type conform to a protocol

references: