Storyboards are now available on OS X Cocoa development

One of the coolest things I love to work with when develop iOS applications is using storyboards. They’re definitely one of the best ways to develop application in my opinion because, they’re very simple and simplify a lot of development tasks, cover most application scenarios and easy to understand as most iOS developers tend to use them.

In recent Apple WWDC (2014), a new version of Xcode (6) has been introduced. This version has a lot of cool features not only for iOS 8 but OS X as well! One of the most surprising features in this version is the support of storyboards for OS X Cocoa development! Using Xcode 6, Mac developers can take advantage of storyboards! Let’s take a look:

Download Xcode 6 from Apple’s developer website. (By the time, Xcode 6 is in beta; consequently, you must be a member of Mac/iOS developer program to be able to download it)

Create a new OS X Cocoa Application. The following window will be appeared:


As you can see in the above screenshot, you now have the ability to create an OS X Cocoa application and use storyboards.

But, you may ask this question: Why this option is disabled here?

Well, the answer is clear! This feature is only available in the latest version of OS X which is by the time OS X 10.10 Yosemite; as a result, you must install it to use storyboards in your applications.

I believe this improvement to Cocoa development, will courage more developers to release the Mac version of their apps. Most iOS developers today have not worked with older technologies such as nib files because when they started iOS development, storyboards were existed and they didn’t need anything else. But now they can do the same thing in Mac applications as they do in iOS.

Hope it helps

Introducing Network Extension in iOS 8 and OS X 10.10

It’s about a year I’m working on an iOS VPN project which enables users to access the web and its contents without any kind of restrictions. By the time, all VPN applications need to install a configuration profile on clients’ devices to apply their VPN configuration on them; because, Apple forbids applications to access iOS system configurations. After the installation of configuration profile, users have to open iOS settings application to enable that VPN service manually; consequently, client applications are act as a profile installer or statistics viewer only!iOS-8-App-Extensions-icon-200x200

The story is completely different on Android devices since restrictions are much fewer than iOS. Android developers can implement a connect/disconnect button to let their users connect and disconnect from VPN servers right from the app.

By introduction of iOS 8, Apple revealed lots of new developer tools and APIs including App Extensions, Handoff, HealthKit, HomeKit, Swift programming language and many many more. But, one of the most useful stuff specially for VPN providers is NetworkExtension which is first introduced in iOS 8 and OS X 10.10!

Network Extension enables developers to manage VPN preferences on their users’ devices. By using this framework, you will have access to almost all iOS VPN preferences. In addition to letting developers access VPN settings, Apple also introduced a new IKEv2 protocol which wasn’t available on iOS or OS X before. This is a standard protocol which is supported by all major mobile and desktop operating systems such as Windows Phone 8.1, Android and now iOS!

I plan to publish more posts about new stuff in both iOS 8 and OS X 10.10. Unfortunately, by now, Apple hasn’t released any documentations regarding Network Extension; but, I’ve done some researches and I’ll share them with you in near future. Until then, please share your idea and information about network extension with me so I can provide a better post to publish :)


Set default sharing accounts in Buffer

I love Buffer services. It comes very handy when you want to share some posts with your friends on social networks. Some people are always have their social network websites’ tabs open in their browsers, whereas others (like me) specified a limited time to check their social networks.

I have added some of my favorite blogs and websites to my Feedly account which I read almost everyday and I like to share them if I find something interesting. Buffer helps me not to share all of them as a same time. It’s Buffer’s job:

Buffer is a great tool that will help you in two main ways. First, you can write a bunch of posts at one time, and choose which social profiles to send them to, and then Buffer will spread them out throughout the day or week so that you don’t have to be at a computer all the time in order to have a social media presence. Second, since we shorten your links for you, we are able to provide more analytics than if you just were to post to Twitter or Facebook directly. For example, we can tell you exactly how many folks clicked on each of your links.

Buffer has extension for all main browsers including Firefox and Google Chrome so it’s much easier to share links you like.

The problem comes to life when you press the share button. The following window will be displayed:

Buffer Share Sheet

As you can see in the above picture, I’ve added three of my social accounts; Facebook, Twitter and LinkedIn. I can click on each one if I wanted to disable sharing for that specified link; but, sometimes you I forget to do so. In most cases, I want to just share the link to my Twitter page. I don’t want to send technical posts to my Facebook page because most of my family and friends which are not developers don’t link them at all.

You click “Add To Queue” without choosing which social network you want to share that link to; Accordingly, it will automatically add that link to all your specified social networks. However, you can remove a link from a specific social network anytBuffer Dashboard Pageime by going to your Buffer account, there’s a very simple way I’ve found on my Buffer account today which can be used to set the default enabled social networks!

To so so, just go to your Buffer account page. All of your linked account are listed there as shown in the picture at right. As you may have noticed, There are check marks on the left side of each account which are all checked by default. These are default sharing accounts’ indicators. You can simply uncheck the accounts you don’t want to be enabled by default in the Buffer’s share sheet. Simple, huh!?

I highly encourage you to try buffer if you use social networks and share links with your friends. Buffer is free but you can upgrade to awesome to get the most of your Buffer.

Recordium is now on AppStore top charts!

Recordium is one of the apps we’re working on at Pichak. It’s getting more and more popular everyday, because users love its unique features. Yesterday we’ve celebrated its first birthday. One year ago, the Recordium released to help users record their moments. It makes it easier to record your voice memos and annotate them at the same time.
10359030_774857019211516_3250373144789554679_oSince it’s Recordium’s first anniversary, we decided to make it Free for a very limited time (It’s still free as I’m writing this post). Hurry!

From the first hours of this promotion, the app rocked the store! We hit number 1 (in productivity and business categories) in some countries including Australia, Germany, and more! Yeah this is pretty impressive!
The following is the latest top charts from the App Store:
14 - 1
I think it’s a good time to say that I am proud of working with such talented people. The team at Pichak spent months to develop something lovely for the users.
Lots of new cool stuff are about to happen in Recordium including lots of new features and improvements. By the time, we’ve released Recordium Mini, a compact version of Recordium Pro for those users who just want to highlight their voices. Lots of good news are coming soon. Stay tuned ;-)

Why don’t you enable comments!?

One of the best tasks I’ve done last week was to revise my Feedly feeds. I removed some feeds which hadn’t been upgraded recently and also added some new feeds. I also came across some Persian bloggers and added their feeds as well.

Yesterday I was reading a post by a blogger about technical matters. I thought I can complete the blogger’s idea by adding a comment. When I wanted to do so, I realized that the comments are closed! When checked other post by that person, I found out that there’s no comment capabilities at all! Why?

One of the biggest purpose of blogging is to share your experience with others. No one in the universe is complete enough; consequently, there might be other thought that can complete your ideas which are posted on your blog. Some of the times, I find my solutions in the comments rather than the post itself.

I know there might be some S P A M M E R s out there which can bother you; but, lot of blog extensions and plugins are available today to reduce them. Comments could also be moderated to avoid inappropriate contexts. There are also other options which can be used like Disqus. It’s a very powerful comment system which can be installed very easily on your blog. It manages all comments on your blog. I also used Disqus on my blog too.

If your blog comments are disabled, please re-enable it to improve your knowledge.

Thank you :-)

How to create installation DMG files in OS X

One of the coolest features of Mac OS in comparison with Windows is the simplicity of apps’ installation. In Windows, in most cases, there should be an installation package; otherwise, the app won’t run correctly. On the contrary, Mac apps installations are much simpler. All you need to do is to copy the app bundle to the Applications folder; so, no installation is needed. The installation process of Skype for Mac is a very good example. To install Skype you just need to drag the app icon into the Applications folder. by doing this, you’re copying the Skype app bundle to your Applications folder. The following is the Skype installation page for OS X:


Now how can you create such installation page for your own app?

First of all, look at the picture above. The installation page contains three major sections:

  • The First is the application bundle (in this case,
  • The second is the OS X Applications folder.
  • The third one is the background image of the installation page.

These three things are the requirements to create a DMG installation file. However, you can ignore the background image and let it be just a solid white color background, it’s much better to have a custom background color or image for your installation page. It make your installer more friendly and of course more beautiful. In addition, there is one more requirement (which is obvious of course): You will need a Mac machine to build DMG installation files. As far as I know, you cannot create DMG installation files in Windows.

Getting Started

After all of three requirements I’ve mentioned above were present, you can get started. I decide to break this tutorial into steps so it’s much easier to understand:

The very first thing to do is to create an empty DMG file so we can put our custom files in it. To do so, OS X has a built-in tool named Disk Utility. You can simply search for it in spotlight search box (On the top right of your screen).


In the Disk Utility home page click New Image button on the top of screen. When New Image button is clicked, a window will be appeared like the following:


There are some settings in the New Image window which need your consideration. The first field is the path of your DMG file that is going to be created. The second field is name. It is recommended to set this field as the name of your application because users will see this name when they mount your DMG file on their machine. The third field is size of disk image. Unfortunately, disk images’ file sizes could not be dynamically allocated so you need to pick a size which is right for your application’s size. It’s recommended to choose a size which is a little larger than your application bundle (The minimum size of disk image is 21MB in OS X). The forth field is image format. This field’s value is set to Mac OS extended by default and there’s no need to change it; so, leave it as it is. Encryption and Partitions fields are fifth and sixth fields in the New Image window which should be left as the default value. We don’t need any encryption or partitioning for now. The last field, Image Format, is sightly important here. You have to set this field’s value to read/write disk image. You won’t be able to create the installation DMG if you select anything else! After setting all fields, click “Create” to create the disk image.

By clicking “Create” your disk image will be created and will be automatically mounted. Close Disk Utility, go to Desktop and double-click on the mounted image to see its content. You can see the disk image is empty as you expected. In the next section we need to fill it by adding our custom files. The reason we’re able to add files to our disk image is because we set the image format field to “read/write disk image”.

It’s time to add our custom-designed background image to our installation (If you don’t want to add an image to your installation page, you can skip this section).
You can simply drag your custom background image to the mounted disk. As you can see the file has been copied to the disk image but has not set as disk image background. To do so, right click on the mounted image on your mac desktop and select Show View Options.

myapp_show_view_optionsThere are two things that need to be taken care of in the Show View Options page. The first one is Icon Size and the second is Background.

Icon Size indicates the size of our two main icons in the installer page (Our two icons are your app bundle icon and the Applications icon). Icon size is completely up to you. In the Skype example I’ve mentioned earlier, the icon size is set to the maximum which is 128*128 pixels. I myself prefer to use the maximum as well; because, it makes it easier for users to do the drag-drop action.

After setting the icon size, it’s now time to set the background image. Just select picture item from background radio button group and then DRAG the image you’ve just copied into the disk image (not from other paths of your hard drive) to the “Drag image here” section. As soon as you drop the image, the background will be set. There’s no Save button. All changes will be saved automatically; so, you can close Show View Options window. You can also resize the disk image window by its corners (as same as what you do when want to resize other windows in OS X) to fit your window size with the background image.

The interesting part is that all of your actions will be kept and the next time you open your disk image, background image, icon size and window size is saved.


As you may have noticed, The image file is in the middle of disk image window. We need to make it hidden so users can’t see it. There are plenty of ways to make a file hidden but one of the coolest ways is to add a “.” to the first of file name. In Unix systems like Mac, files which are started by a “.” are hidden by default. You can’t change the file name in the finder. You need to rename the file in terminal. So open a terminal window and do the following:


As you can see the file is now hidden!
The next step is to copy our app bundle. To do it just copy the app bundle to your disk image. You can also change the location of app bundle to any place of disk image we want. After the bundle has been copied, We need to make an Application icon so use can drag the app to it. To do so, go to you Macintosh HD, click on Applications, hold Command and Option key, and dray it to the disk image window. By holding Command+Option it will make an alias of that folder. Note that we’re not copying the Applications folder, we’re just making an alias from it. Place the two icons near each other so it’s easier for users to install the app.

We’re almost done. Your installation DMG file is ready; but, there is something. By publishing this DMG file, all users can change its background image, icon size, window size, and etc. In fact, they can do whatever you can! To prevent this, we need to make this disk image read-only.
Eject the disk image by right-clicking on disk image icon and selecting “Eject”. Re-open the Disk Utility tool again. On the left side of Disk Utility home pas select the DMG file we’ve created, then, select Convert. The convert window will show up. select a unique name for it and from Image Format select read-only. Click save to create a new disk image from your selected one. The new DMG file we’ve just created is read-only can be safely published and others cannot make changes to it.

If you have any question, don’t hesitate a moment; just ask it on the comments down below :-)
Hope it helps.

Run a bash command in Objective-C

During the last month, I’ve been very busy developing apps for iOS and OS X. OS X development was very enjoyable and interesting for me since it was my first time developing Mac applications. During this development, I’ve learned lots of things. some of them were very basic concepts while some were very complicated. The app I was developing needed to execute bash commands to access sensitive parts of OS X, so I had to have a function for calling these bash commands and in this post I’m going to share my experience with you :)

First of all you need to create a NSTask object.

Using the NSTask class, your program can run another program as a subprocess and can monitor that program’s execution. An NSTask object creates a separate executable entity; it differs from NSThread in that it does not share memory space with the process that creates it.

NSTask *task = [[NSTask alloc] init];

Then you have to set the file or path that has to be executed using setLaunchPath: method. To make my code clean, I prefer to create a new variable called path and assign the process’ launch path to it. In this case I’m going to launch the ping command:

NSString *path = @"ping";
[task setLaunchPath: path];

As you may know the bash’s ping command requires an argument which is the destination’s IP address or host name that want to be pinged. So we need to pass an argument to our NSTask object. NSTask has a setArguments: method which accepts an array of objects. So we have to create an NSArray first and then pass the array to the setArguments: method:

NSString *pingParam = @"";
NSArray *args = [NSArray arrayWithObjects: pingParam, nil];
[task setArguments: args];

You can now run the task using [task launch]; method; but, if the command you’re executing had a return value, you won’t get it. Thus, you need to create an output. NSPipe is an standard output you can use to get the results. You have to tell the task you’ve created what kind of outputs you want to use.

NSPipe objects provide an object-oriented interface for accessing pipes. An NSPipe object represents both ends of a pipe and enables communication through the pipe. A pipe is a one-way communications channel between related processes; one process writes data, while the other process reads that data. The data that passes through the pipe is buffered; the size of the buffer is determined by the underlying operating system. NSPipe is an abstract class, the public interface of a class cluster.

NSPipe *pipe = [NSPipe pipe];
[task setStandardOutput: pipe]; //Telling the task object what output to use.

Now the return value of our task will be passed to the pipe object. Now we need to get this value. To do so, we need to make use of NSFileHandle object.

The NSFileHandle class is an object-oriented wrapper for a file descriptor. You use file handle objects to access data associated with files, sockets, pipes, and devices. For files, you can read, write, and seek within the file. For sockets, pipes, and devices, you can use a file handle object to monitor the device and process data asynchronously.

NSFileHandle *file = [pipe fileHandleForReading];

Now we can safely run [task launch] method and launch the task. After launching, we need to get the value which is returned. When [task launch] is called, it stops the main thread until the results are returned. Although, you can make the task launch asynchronous if you want but in this example the application waits until bash results are returned.
After the process has been successfully launched, it puts the results in the NSFileHandle we’ve just created. By default, results are in NSData format because it could be any type of data. In this case, the result of a ping command is nothing but a NSString, as a result, we need to convert the NSData to NSString:

NSData *result = [file readDataToEndOfFile];
NSString *resultString = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
// Your result is ready. We want to just print it by using NSLog command:
NSLog(@"The result is: %@", resultString];

Done! Your bash command is executed and the results are returned.

Hope it helps.

How to use Entity Framework to connect to a MySQL database

In my previous post I blogged about the importance of choosing the best database platform for your project. As database platforms are usually very expensive and more than 80% of the applications you’re developing are small size, you need to choose an affordable database platform and as I described in my previous post, MySQL is one of the best choices.

There’s no doubt that Microsoft.NET framework is one of the best framework for developing apps no matter what kind of app you’re going to develop. But sometimes you need to use a different database platform. Most of .NET developers are using Microsoft SQL Server as their database back-end. In this post I want to tell you how to connect to a MySQL database and use it alongside Entity Framework.

Note: I am using Microsoft Windows in this post. You cannot use this post’s instructions if you’re using Linux or Mac because as the time of writing this post, Entity Framework cannot be installed and used with Mono Develop or Xamarin Studio.

Getting Started

The first thing you need is obviously MySQL Server. MySQL Server is a service which runs on your machine and enables you to have MySQL functionality and it’s available to download from MySQL download center.

After installing MySQL Server it’s possible to connect to it via Windows Command Prompt but it’s such a pain in the neck! So you need to use something like Microsoft SQL Server Management Studio (SSMS) to connect to your database server. There are bunch of free/open source applications you can use which work like SSMS. For example, phpMyAdmin is a free tool you can use to access your MySQL database on the web. But I recommend you to use MySQL Workbench!

MySQL Workbench is a unified visual tool for database architects, developers, and DBAs. MySQL Workbench provides data modeling, SQL development, and comprehensive administration tools for server configuration, user administration, backup, and much more. MySQL Workbench is available on Windows, Linux and Mac OS X.

It’s very cool and easy to use tool to connect to your MySQL database and it can be downloaded from here.

Now it’s possible to just connect to your database by using MySQL Workbench and then create you first database. While this post is not going to cover T-SQL stuff, I assume that you know T-SQL enough as you can create a database named “test”, a table named “test_table” with two columns as shown below in it:

My SQL Workbench table scheme

Also add a new record with id of “1″ and name of “It works!” to the table you’ve just created so we can test whether we’re connect to the database or not.

Now your database is ready. The next step is to make Visual Studio ready as well! In order to connect to a MySQL database, you’ll need to install two things:

  1. MySQL connector for Visual Studio: This is the main library to access MySQL from Visual Studio. Even if you’re not going to use Entity Framework, you need to install this component.
  2. MySQL for Visual Studio: It’s a Visual Studio plugin that has to be installed when want to connect to a MySQL database via Entity Framework.

After installing MySQL tools for Visual Studio, it’s time to launch Visual Studio and create a console application and call it mySqlTest.

After new application created, right-click on your project in Solution Explorer, point to Add and select New Item. In the window appears, select “ADO.NET Entity Data Model” from the list,change the name to “DataModel.edmx” and click Add as shown below:

Select ADO.NET Entity Data Model

By clicking Add button, Entity Data Model Wizard will be opened:

Entity Data Model Wizard

Select “Generate from database” and click next. A new window will be opened and ask you for the database connection.

This is the most important part of connecting to a MySQL database. Click on “New Connection” button. The “Connection Properties” page will be open to ask you the server name you’re going to connect to. The first field in the Connection Properties page is the data source. By default data source field is set to “Microsoft SQL Server (SqlClient)” but to connect to a MySQL database, you need to change it; so, click on “Change” button. By clicking the “Change” button, “Change Data Source” Window will be appeared:


Select “MySQL Database” and then click “OK”. When “OK” is clicked, a new window will be opened to ask you about your database credentials which has 3 major fields.

The first field is “Server name”. If MySQL is installed on your local machine, just type “localhost” in the “Server name” field. The next two fields are database username and password. These fields are required to connect to your database. After filling all 3 fields, click “Test Connection” to see if everything is OK and the click “OK”. As a result, Visual Studio creates the connection string for you. just click “Next”.

The next window asks about the database objects you’re going to add to the data model. As we have only one table “test_table”, just check Tables node and click “Finish”.

You’re almost done! Now open “program.cs” file and add the following lines of codes to the main function:

DataModelEntities db = new DataModelEntities();

Now run the app by pressing F5. If everything is correct, you must see the following:


Now you app is connected to a MySQL server via Entity Framework. You can now add,edit,delete or do anything else using entity framework.

Hope it helps

Choosing the best database platform for your project

Choosing the best platforms which covers all of your project’s needs is one of the most important tasks to do before starting every project. You have a very important decision to make because it’s the platform you’re going to work with until end of project. Many decisions need to be made before getting started but this post covers one of them; the database!

Beside operating system, database platform is the most expensive part of your project. Some of the databases’ licenses are very expensive. For example, if you take a look at Microsoft SQL Server pricing page you will notice that the enterprise edition of SQL Server 2012 price is $6,874 per core! Which means, if you want SQL Server to use all of your server’s resources and assume that your server has a four-core processor, you’ll have to pay about $27,496 which is seriously expensive.

Unfortunately, In my country (Iran), most of developers don’t care about pricing because the lake of copyright. A few month ago, I saw a web server in Iran which had SQL Server 2012 Data Center edition without paying ever $1! Most Iranian developers prefer to use SQL Server in their projects because of three main reasons:

  • .NET Framework is very very popular among Iranian developers. It’s also very easy to learn.
  • Pricing/Licensing is not important due to the lake of copyright.
  • SQL Server is integrated with Microsoft technologies like .NET. As a result, it’s the easiest choice for .NET developers.

Anyway and beside pricing/licensing, choosing a database platform depends on lots of things. Here are some:

Size of your application

Unfortunately, some developers don’t care about it often. The want the best for all of their solutions. For instance, a while ago, I saw a personal website which was using SQL Server 2008 Enterprise edition as its database back-end. It’s obvious that a personal website doesn’t need a database this big! However, if you’re developing a large application such as banking and accounting apps you will need to use a powerful database. My previous blog was using XML as data source. It was enough for my website and I never felt I need more. If you think you want more than XML, you can try using SQLite or MySQL which are both free. SQL Server also has an Express edition which is free too.

Your server’s hardware configuration

Believe me, there’s no need to install a very heavy database platform on a server with only 1 GB of RAM! While Enterprise editions have the most, they use more resources as well. For example, if you’re using a VPS with only 2 GB or RAM and a single core of CPU to host your website, you should not install Oracle Enterprise edition. It slows down your server so other calculations will get slow too.

Your server’s OS

Another important things to consider is the server’s operating system. Some of database platforms are cross-platform (which means they can be installed on any operating system) and some are not! For example, Microsoft SQL Server can be only installed on Windows and you cannot install it on other operating systems like Linux or Mac whereas Oracle is cross-platform. You can design and implement your database on a windows machine and then deploy it on a Unix server which is pretty cool.


Choosing a database platform is very important before starting a project. There are many factors you should consider while choosing a database platform. More than 80% of websites and applications are small-sized; therefore, you should not use heavy and expensive databases. I believe MySQL is the best choice. It’s open-source, free and highly scalable. It covers all of my needs and it can be installed on any server no matter what operation system is installed.

I think you should reconsider about the database you’re using and change it if you think it’s more than you want ASAP before it gets too late.

If you’re using Flurry, update it before submitting your app to the AppStore

Previously, I blogged about how awesome is Flurry, a free analytics system you can use in your mobile apps. I also blogged about why Apple rejected my app and made me resubmit my app. In that post, I’ve described the reason Apple rejected my app was because of using AdSupport.framework.

After cleaning my app from AdSupport.framework and resubmitting it to the AppStore, I got rejected again! So I started to argue with apple and also searched a lot on the internet until I found this StackOverflow question. People were arguing that Apple also rejected their apps too because of using AdSupport.framework whereas they haven’t used it in their applications!

As a result, I decided to contact Flurry support to see if there’s any problem with their SDK. When I logged in to my Flurry account, I saw this:


It seems Flurry was also using AdSupport.framework for device identification and since Apple forbids it, they updated their SDK as well :-)

Therefore, if you’re using third-party SDKs such as Flurry you need to update to the latest version before submitting your app to the AppStore. As far as I know, By the time, other third-party libraries like Google Analytics, Facebook SDK and TestFlight are also having this issue and you should get their latest SDK to prevent your app from being rejected.