How to Run Mac OS X 10.10 VM on VMWare Workstation 11

More and more companies tend to release products for both Mac and Windows platforms. If a Windows developer wants to create apps for Mac OS, the most economical way is to use a virtual machine. When I upgraded my operating system from Windows 7 to Windows 10 and installed VMWare Workstation 11, I found my Mac OS X virtual machine couldn’t work.  Here are the issues and corresponding solutions.

Read more

How to Bridge C Code to Create Swift Barcode Reader on Mac

Have you implemented any barcode reader software in Swift on Mac OS X? Since Dynamsoft released the 1D/2D barcode SDK for Mac, I was wondering how I can bridge the C dylib with Swift. Why Swift, not Objective-C? Because Apple is encouraging developers to migrate to the new programming language, it is important to master the new tool if you want to create more excellent apps for Mac and iOS in the future. Swift is totally new to me, and thus I spent two days googling relevant resources and finally figured out the solution.

Read more

Getting Started with JNI on Android, Windows and Mac

Java Native Interface (JNI) is the glue between Java and native code such as C, C++, and assembly. With JNI, Java applications are capable of supporting platform-specific features. JNI enables developers to call low-level APIs (e.g. SQL, OpenGL etc.) to make Java application more powerful with higher performance. For example, we can download a JDBC driver, and unzip the jar package to take an insight. The driver is not written in pure Java. It also contains native libraries for Linux, Mac, and Windows.

jdbc

Since JNI is so useful, I’d like to share how to get started with JNI on Android, Windows, and Mac.

JNI on Android

Download NDK and configure the location in Eclipse:

android JNI

Create a new project named hellojni. To automatically generate the native C/C++ code and configuration file, you just need to right-click on your project and select Add Native Support:

add_native_support

After that, a JNI project will be automatically generated. To build the shared library, you just need to implement JNI methods in C/C++, and add configurations in Android.mk.

jni_folder

When you save all changes, the shared library libhellojni.so will be automatically generated. You can also build the library by typing in ndk-build.ndk_build

JNI on Windows

Create a Win32 project named hellojni in Visual Studio:

Read more

How to Create a Background Service on Mac OS X

As a Windows developer, I spent some time looking for an efficient way to create a service, as a counterpart of Windows service, on Mac OS X. Referring to the online documentation – Designing Daemons and Services, there are four types of background processes. The type Launch Daemon satisfies my requirements: running in the background with no access to the window server. In this article, let’s go through the process of creating a Launch Daemon on Mac OS X.

Mac Background Service: Launch Daemon

  1. Launch Xcode, and create a command line application named WebTwainService.
    #import <Foundation/Foundation.h>
    
    int main(int argc, const char * argv[])
    {
    
        @autoreleasepool {
    
            // insert code here...
            NSLog(@"Hello, World!");
    
        }
    
        while (1)
        {
            sleep(100);
        }
        return 0;
    }
  2. Build the project, and move the executable file WebTwainService to /Applications/Dynamsoft/WebTwainService.
  3. Referring to Create Launch Daemons and Agents, create a configuration file com.dynamsoft.WebTwainService.plist.service_plist
    • StandardErrorPath & StandardOutPath: service log file path
    • KeepAlive. Set it true. When WebTwainService crashes unexpectedly, the system will automatically re-launch the service.
    • Label: unique value.
    • ProgramArguments: executable file path.
  4. These folders are where the plist should be placed:
    • ~/Library/LaunchAgents: Per-user agents provided by the user.
    • /Library/LaunchAgents: Per-user agents provided by the administrator.
    • /Library/LaunchDaemons: System-wide daemons provided by the administrator.
    • /System/Library/LaunchAgents: Per-user agents provided by Mac OS X.
    • /System/Library/LaunchDaemons: System-wide daemons provided by Mac OS X.
  5. Move com.dynamsoft.WebTwainService.plist to /Library/LaunchDaemons.
  6. To register service successfully, we have to modify the file permissions. Otherwise, we’ll receive the error message: launchctl: Dubious ownership on file (skipping). Launch terminal and type in the command sudo chown root  /Library/LaunchDaemons/com.dynamsoft.WebTwainService.plist.service_permission
  7. Type in sudo launchctl to run launchd:service_launchd
  8. Register plist with command load -D system /Library/LaunchDaemons/com.dynamsoft.WebTwainService.plist. Then we can see our service has been loaded.
    service_loaded
  9. Type in the list to check whether the service is running.service_run
  10. Now, reboot the system to verify whether the WebTwainService can work. Open /var/log/webtwain.log
    service_log

Source Code

WebTwainService

How to Configure and Install Nginx on Mac OS X

In this tutorial, I would like to show how to configure and install nginx on Mac OS X. My Mac system is Mavericks 10.9.2.

mac environment

Prerequisites

You have to install Xcode command line tools.

Install Nginx

1. Download the latest stable version – nginx 1.4.7.

2. Unzip the downloaded package by the command “tar xvzf nginx-1.4.7.tar.gz”.

3. “cd nginx-1.4.7”.

4. “sudo ./configure”. There is an error displayed:

./configure: error: the HTTP rewrite module requires the PCRE library.

You can either disable the module by using --without-http_rewrite_module

option, or install the PCRE library into the system, or build the PCRE library

statically from the source with nginx by using --with-pcre=<path> option.

5. To fix the error, visit the tutorial page and read “Building nginx from Sources”, in which you can find the link of PCRE library.

6. Go to PCRE official site, and find the latest version of PCRE library on SourceForge.

7. Download the package and unzip it by the command “tar xvzf pcre-8.34.tar.bz2”.

8. Now, you can run the configure file again with the parameters  “sudo ./configure –with-pcre=path”.

9. Configuration is done.

  nginx path prefix: "/usr/local/nginx"

  nginx binary file: "/usr/local/nginx/sbin/nginx"

  nginx configuration prefix: "/usr/local/nginx/conf"

  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"

  nginx pid file: "/usr/local/nginx/logs/nginx.pid"

  nginx error log file: "/usr/local/nginx/logs/error.log"

  nginx http access log file: "/usr/local/nginx/logs/access.log"

  nginx http client request body temporary files: "client_body_temp"

  nginx http proxy temporary files: "proxy_temp"

  nginx http fastcgi temporary files: "fastcgi_temp"

  nginx http uwsgi temporary files: "uwsgi_temp"

  nginx http scgi temporary files: "scgi_temp" 

the default nginx path prefix is “/usr/local/nginx”.

10. To install nginx, type in “sudo make install”.

11. Find the executable file “cd /usr/local/nginx/sbin”

12. Launch nginx “sudo ./nginx”

The nginx is successfully running now!

nginx running

If you have any questions, just email {desmond at dynamsoft dot com}.

 

Is the Age of Free Operating System Coming?

There was news earlier this week that Apple will be providing its latest operating system, Mavericks, for free. It is apparently good news to just about all Mac users. There are also sure to be some people that may wonder whether this is a strategy against Microsoft. Just a couple of days ago, Microsoft announced that it would not charge consumers who upgrade their OS from Windows 8 to Windows 8.1.

For most consumers, there is nothing more important than an acceptable price point. Who doesn’t want to have a free meal? Apple began to drop OS prices starting with version 10.6 of Snow Leopard, which at the time was around $29 for the upgrade. It keeps getting lower and lower with each new release. Version 10.8 is currently $19.99. It’s well known that the operating system and Office suite are very significant products for Microsoft. They have been a primary source of Microsoft’s revenue to date. However, the OS and Office business is shrinking. There’s considerable agreement that what Apple is doing is having a huge impact on these Microsoft products.

Besides the free OS, Apple also announced that iLife and iWork are both free for consumers who purchased the latest Mac and iOS devices. So how will Apple then make a profit? Apple has established an excellent ecosystem with the Appstore for developers and consumers. This business model consists of advertisements, in-app purchases and cheap apps. With billions of consumers and probably hundreds of thousands of developers in hand, it is pretty easy for Apple to make money.

Also, the effective marketing of the booming mobile market is having a big influence on the PC market. Apple, as the pioneer of the smartphone, is trying to fuse their mobile OS and desktop OS with consistent experiences. To this end, it seems Apple decided to make the desktop OS free, just like the mobile OS. It is also a good approach to try and attract more consumers to the Mac platform, especially when comparing it to Windows’ price.

So, Apple is making a profit with hardware and services and this is Apple’s unique business model. Let’s think about what Google is doing. Google’s Nexus series may be the cheapest mobile devices in the world and its Android operating system is even open-source. The OS is provided to transplant to any hardware, including mobile devices, TVs, vehicles, fridges, and so forth. So, even Google is about the service and not making money on the OS. For example, most apps in the Apple or Google platform are free now. They instead depend on added value in apps or ads for income. Another typical example can be seen in telecommunications. Here consumers sign up for a service contract for a period of time to get a cellphone for free. Instead of paying for hardware they pay for service – they pay for their call and data usage plans each month. This is an established business model in telecommunications that earns them more money.

In the end, the competition between these giant companies benefits consumers. It spurs new technology and changing business model that address consumer wants. Perhaps it has even ushered in the age of the free operating system.