Swift Tutorial to add library framework from Github

This tutorial explains how to add library framework from Github.

Imagine you refer to this page that having list of frameworks, and you would like to install one of the library, such as SwiftHTTP.

Step 1:

Go to the root folder of your application.

Run git submodule add <Github URL>

E.g. git submodule add https://github.com/daltoniam/SwiftHTTP

Step 2:

Open SwiftHTTP folder under the root folder of your application.

Drag SwiftHTTP.xcodeproj to your XCode Project.

Refer to below picture, drag SwiftHTTP.xcodeproj to Chats, the top level hierarchy of project.

Step 1 Drag xcodeproj to Project hierarchy

 

Step 3:

Click on SwiftHTTP.xcodeproj that added to your project hierarchy.

Check Deployment Target under General Tab.

Make sure it is the same with your application’s deployment target.

Step 3 Check Deployment Target

 

Step 4:

Click on your main application, under Build Phases Tab, click “+” under target dependencies section.

The end result is something like this.

Screen Shot 2014-12-22 at 7.53.12 pm

Step 5:

Add a new phase by clicking “+”  under Build Phases Tab, and choose “New Copy File Phase”, change the name to “Copy Frameworks”.

Screen Shot 2014-12-22 at 7.54.24 pm

Step 6:

Under the new phase “Copy Frameworks” added in last step, destination choose “Framework”, and add the frameworks.

The end result something like this

Screen Shot 2014-12-22 at 7.56.12 pm

 

Then test your code with the library:

 


var request = HTTPTask()
var params = ["k": "q:name=currency,stat=swift", "api" : "1", "server_host" : "swift"]
request.requestSerializer.headers["X-Mashape-Key"] = "Ri4j5gX4ORmshweHbjBSUUMevXWIp1i0xRujsnjCz7wW9w5zLB"
request.GET("https://imgshow-platform.p.mashape.com/", parameters: params, success: {(response: HTTPResponse) in
if let data = response.responseObject as? NSData {
let str = NSString(data: data, encoding: NSUTF8StringEncoding)
println("response: \(str)") //prints the HTML of the page
}
},failure: {(error: NSError, response: HTTPResponse?) in
println("error: \(error)")
})

 

Enhancing my personal reminder apps with outbounds calls feature

I had my own personal reminder apps for years. This reminder apps is greatly improving my schedule in workings and personal. I use the apps to remind me when to pay rent, when is the meeting held, and so on, day to day.

This is a simple reminder apps simply managing a list of tasks. I can configure a task name, start end time (hhmm format, such as 1000), a reminder text, then enter enabled field as 1 (To enable 1, To disable 0). Then I would configure the system check for the reminder every 10 min. If the current time drop between the start end time, it will simply remind me by sending an Apple APN Notification or Google GCM Notification.

Reminder Iphone Sample Task

I did built an outbounds call features last year using Freeswitch Outbounds SIP. But it is not user friendly as, I have to open the SIP Phone all the time in order to receive the outbounds call. I wonder why Apple do not have SIP built in into system core, like Samsung Phone.

Since this morning I just figure out to make outbounds calls to landline or cellphone from Freeswitch, therefore I would like to enhance my personal reminder apps with outbounds call feature.

When the time arrive, it will try contact me and announce the reminder text I configure that task.

It is not feasible to call me every 10 min, so I made it to have the task to only call me one time and it will going to sleep after that.

When creating the task, if enter “enabled” as 1, it will perform usual action, notify me via Apple APN. If enter as 2,  it will make outbounds call service. After made calls, update back to 0 to disable the task.

In this simple reminder apps system architecture, I greatly adopt microservice style. Each service itself is self-managed (start/stop/status individually), and only do a single task. Then they are able to support other apps if configure the way and the working flow. Like the reminder apps is actually a single service to schedule the tasks, have an admin interface to manage it. Cron job apps is another service to schedule HTTP cron job URL, have an admin interface to manage it, I created Reminder Apps Cron Job to trigger the reminder apps checks. Apple APN is another single service that send APN notification to Apple. Google GCM is another apps is another service to send message to Samsung (Sometimes I closed it when I am not in Malaysia). Today, a new service is created, is for outbounds call web service. Most of the web service I created here, are using Node.JS as server side, and Titanium Mobile (iPhone apps), and all using JavaScript. A little web service are using Java back end. All web services are secured using API Keys and Password Authentication for cross communication.

Freeswitch Outbounds call provider settings

FreeSWITCH is a scalable open source cross-platform telephony platform designed to route and interconnect popular communication protocols using audio, video, text or any other form of media.

To setup Freeswitch Outbounds call to landline or cell phone, must go through a PSTN or SIP gateway. Didlogic provides DID and SIP gateway.

This tutorial is going to configure SIP gateway on Didlogic, and configure the necessary settings in Freeswitch, in order to make outbounds call to landline or cellphone.

The step 1. Register an account on Didlogic and navigate to SIP Tab (https://didlogic.com/sipaccounts).

Create a SIP Account you will get SIP Username, Password, and you may set a caller ID from a list of DID you registered.

DIDLogic SIP Profiles

 

The step 2. You may navigate to Didlogic ‘s provided Freeswitch Configuration page (https://didlogic.com/support/setup-guides/freeswitch-config).

What we want is Freeswitch General Config


<include>
<gateway name="didlogic">
<param name="username" value="12354"/>
<param name="realm" value="sip.didlogic.net"/>
<param name="password" value="your_SIP_password"/>
<param name="register" value="true"/>
<param name="context" value="public"/>
</gateway>
</include>

Replace it with your SIP account username, and password created in Didlogic SIP Accounts Page.

The step 3. Go to your Freeswitch installation directory, for example, installed in a Linux box the location will be: /usr/local/freeswitch/conf/sip_profiles/external

Vi didlogic.xml, and paste the contents above, and :wq! to save the file.

If your Freeswitch is open and running, go to /usr/local/freeswitch/bin/fs_cli, then type reloadxml, it will reload the xml configuration.

Now, you can make a test call.

The step 4. You may go to /usr/local/freeswitch/bin/fs_cli, type:

originate sofia/gateway/didlogic/65xxxxxxxx ''

Then your phone will get the call. You will see the caller id is the same you defined at Didlogic SIP Profiles page.

For advanced Caller ID settings in Freeswitch, I not tried, you need have a verified business custoemr in Didlogic, then you can follow this tutorial https://didlogic.com/support/setup-guides/freeswitch-own-cli, then you may be able to configure your custom CLI.