Skip to main content

Posts

Hướng dẫn thiết lập Google Tag Manager với Google Analytic trên ứng dụng iOS

Google Tag Manager là gì? Google Tag Manager (GTM) là bên trung gian giữa những ứng dụng của Google như: Google Analytics, Google AdWords, DoubleClick... Chỉ một vài động tác thiết lập bạn có thể liên kết những tài khoản đó lại với GTM. Sau khi bạn đã liên kết những tài khoản đó lại, mỗi khi ứng dụng của bạn gởi request lên GTM, GTM sẽ tự động gửi dữ liệu đó đến những dịch vụ tương ứng (Ví dụ như: Google Analytics để phân tích hành vi người dùng). GTM cho phép bạn thay đổi những thiết lập đó tại bất kỳ thời điểm nào chỉ với vài động tác nhấn chuột mà không cần phải build lại ứng dụng. Vì thế bạn không phải sợ bỏ lỡ công việc đo lường  hoặc việc kinh doanh của mình. Ưu điểm: - Bạn có thể gởi 1 request lên GTM để GTM tự động gởi những thông tin đó đến những service khác như Google Analytics, Google AdWords, DoubleClick... - Bạn có thể sửa mà không sợ ảnh hưởng đến ứng dụng đang chạy. Nhược điểm: - Khó thiết lập được hết những chức năng của service trong GA, AdWords, DoubleClick. - Bạ...

(CI) Jenkins PMD report for Objective-C with OCLint

OCLint is a  static code analysis  tool for improving quality and reducing defects by inspecting C, C++ and Objective-C code and looking for potential problems like: Possible bugs - empty if/else/try/catch/finally statements Unused code - unused local variables and parameters Complicated code - high cyclomatic complexity, NPath complexity and high NCSS Redundant code - redundant if statement and useless parentheses Code smells - long method and long parameter list Bad practices - inverted logic and parameter reassignment ... Installation: Step 1 : Download "oclint-0.x.x-x86_64-darwin-15.0.0.tar" from the downloads page . Unzip this file and see as below: Step 2: Copying OCLint to System PATH. Open Terminal prompt, and input some commands lines as follows: $ cd /Downloads/oclint-0.10.x $ cp bin/oclint* /usr/local/bin/ $ cp -rp lib/* /usr/local/lib/ Other option: Directly adding to PATH at here . Checking installation:   Open a new terminal prompt, and execute  o...

Improve Unit Test with OCMock

Adding OCMock to your project: Step 1: Download a release from the  downloads page . Step 2: Setup OCMock from the  iOS page . Step 3: Add an import to your unit tests. #import <OCMock/OCMock.h> Contents: Example classes Expect-run-verify Verify-after-running Void-Method Return-Method Block Delegate and DataSource Notification (Observer) Exception Advanced topics 1. Example classes Let's assume we are writing a little application. Our application have two classes as ClassA and ClassB. ClassB inherit from ClassA. They have some methods as below: 2. Expect-run-verify This is the original approach to mocking. First the mock object is set up with expectations, then the code under test is run, and afterwards the expectations are verified. If an expected method has not been invoked, or has not been invoked with the right arguments, then an error is reported. As shown it is possible to use argument constraints in the expect statement. Strict mocks can be created for classes and...

[Tip] Simulate various network conditions with "Network Link Conditioner"

Xcode provides a tool called Network Link Conditioner that can simulate various network conditions , including reduced bandwidth, high latency, DNS delays, packet loss, and so on. Before you ship any software that uses networking, you should install this tool, enable it, then run your software to see how it performs under real-world conditions. Here are a few things to test: Make sure your software remains usable even with lousy bandwidth. Tune your bandwidth consumption as much as you can. Increase the latency to three or four seconds. Make sure that any user-initiated operation is delayed by only a few seconds, not by a few minutes. When the network connection drops packets, your software should continue to function, just more slowly. Enabling  Network Link Conditioner  on iOS device: - Step 1: Open Settings -> Select Developer -> Select Status in group name ( Network link conditioner ) : - Step 2: Enable Network Link Conditioner -> Choose a profile of network ...

[Structural Pattern] Adapter pattern trong Objective C

Khái niệm: chuyển đổi interface của một class thành interface khác mà bạn trông đợi, để có thể tương thích với những interface đã có sẵn trước đó. Adapter cho phép những class hoạt động chung với nhau bất kể những interface của những class không tương thích với nhau. Cấu trúc lớp: Ví dụ mình có sơ đồ lớp như sau: - Adapter theo quan hệ Navigability hoặc Aggregation hay Composition như nhau: - Adapter theo quan hệ kế thừa Generalization hay Realization như sau: Cách sử dụng: Chúng ta thường dùng Adapter trong việc bảo trì ứng dụng. Chúng ta không thể viết code vào những đối tượng có sẵn trước đó nhưng vẫn phải đảm bảo hệ thống chạy tương thích với những lớp đó hay có thể sửa mới thì chúng ta ứng dụng Adapter vào. Code ví dụ trong Objective C:

[UML Class relationships] Phân biệt quan hệ Generalization và Realization trong Objective C và Swift

2 quan hệ này tương đối dễ phân biệt và thực thi. Generalization :  giống quan hệ kế thừa trong những ngôn ngữ lập trình. Theo sơ đồ trên thì ClassB đang kế thừa ClassA Code ví dụ trong Objective C : Code ví dụ trong Swift: Realization :  là quan hệ thực thi 1 interface. Theo sơ đồ trên thì ClassA thực thi những chức năng được định nghĩa sẵn trong InterfaceA. Code ví dụ trong Objective C: Code ví dụ trong Swift:

[UML Class relationships] Phân biệt quan hệ Aggregation và Composition trong Objective C và Swift

Aggregation ClassA có dùng lớp và giữa ClassB nhưng không cho lớp khác truy xuất ClassB thông qua ClassA.  Trong Objective C ta dùng thuộc tính là weak để thể hiện mối quan hệ này, code ví dụ như sau: Ngoài ra ta còn có sơ đồ Aggregation - Navigability: Theo sơ đồ này thì ta dùng property để lớp khác có thể truy xuất ClassB thông qua ClassA. Code ví dụ trong Objective C như: Unit Test giả sử ta huỷ đối tượng ClassB thì ClassA sẽ không gọi hàm trong ClassB được, do đó trong sơ đồ này nên dùng if để kiểm tra đối tượng khi truyền vào để tránh bị crash ứng dụng: Code ví dụ trong Swift như sau: Composition Composition giống như Aggregation nhưng giữ đối tượng theo kiểu strong, thì sẽ không phụ thuộc vào đối tượng truyền vào. Giống code ở trên nhưng ta thay weak thành strong thì sẽ thể hiện mối quan hệ này , ví dụ như sau: Cũng viết UnitTest như trên nhưng kết quả khi huỷ object tham chiếu thì đối tượng đó vẫn được giữ lại để thực hiện phương thức: Code ví dụ trong Swift như sau: Tà...