Thursday, June 28, 2012

php simple websocket client


hi

i experiencing websocket connections using php,nodejs for server side and using jquery for client side, soon i hope to publish my simple experiments for others newbies. for now i with this simple php script that i used to debug my apps it's a simple client that send data to nodejs http.server and stamp
the response received i hope that for someone it will be useful

Kevin Pham

the code:

<?

 $host = 'localhost';  //where is the websocket server
 $port = 9000;
 $local = "http://localhost/";  //url where this script run
 $data = 'hello world!';  //data to be send

 $head = "GET / HTTP/1.1"."\r\n".
   "Upgrade: WebSocket"."\r\n".
   "Connection: Upgrade"."\r\n".
   "Origin: $local"."\r\n".
   "Host: $host"."\r\n".
   "Content-Length: ".strlen($data)."\r\n"."\r\n";
 ////WebSocket handshake
 $sock = fsockopen($host, $port, $errno, $errstr, 2);
 fwrite($sock, $head ) or die('error:'.$errno.':'.$errstr);
 $headers = fread($sock, 2000);
 fwrite($sock, "\x00$data\xff" ) or die('error:'.$errno.':'.$errstr);
 $wsdata = fread($sock, 2000);  //receives the data included in the
websocket package "\x00DATA\xff"
 $retdata = trim($wsdata,"\x00\xff"); //extracts data
 ////WebSocket handshake
 fclose($sock);

 echo $retdata  //data result
?>

Objective-C creating objects, methods and variables

In this tutorial we will be creating a console application to try every part of our code out. Please make sure that the console is not set to its default language, which is C and is instead set to foundation.
The first thing we need to do is create a no project with Xcode. I will be naming mine “test” but you really don’t need to follow along with that much detail since it is not needed at this stage with the level of coding we will be doing.
The next thing we will need to do is open up our “test.m” file through Xcode. This file contains the default main method but we are going to be creating objects and variables.

Monday, June 25, 2012

Eclipse Indigo for Android Development on Mac OS X Snow Leopard

I decided to install the latest version of Eclipse, Indigo, and configure it to do Android application development. My specific final target is to build the VLC Player for Android. Below are my notes for installing such an Eclipse configuration for Android development on a clean Mac OS X Snow Leopard system.
Install Android SDK
  1. Download latest Android SDK (I downloaded “android-sdk_r12-mac_x86.zip”).
  2. Unzip and move the extracted “android-sdk-mac_x86″ directory to “/Applications”, so you end up with “/Applications/android-sdk-mac_x86″.
  3. Add the following to the end of your bash environment configuration file “~/.profile”. (The tilde symbol ~ translates into your home directory “/Users/your_username”.)
    export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home
    export ANDROID_SDK=/Applications/android-sdk-mac_x86
    export PATH=$PATH:$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools
    export NO_NEON=1
    Some details on the above:

Saturday, June 23, 2012

How to Send an SMS Progammatically

This post shows the basics for sending an SMS message from within an iPhone application. The class you’ll need to use is MFMessageComposeViewController which presents the standard SMS interface for composing and sending messages. As you’ll see in the example that follows, you can also pre-populate the body of the message as well one or more recipients for the SMS.
SMS View Controller Interface
The view controller that will send the SMS is shown below, notice the message composer import statement as well as the reference to the protocolMFMessageComposeViewControllerDelegate. The delegate has just one method where you can check the result of the message (sent, cancelled or failed) and this is also where you dismiss the view controller show the message composer – more on this method in a moment.

Thursday, June 21, 2012

Capture screenshots on Mac OS

Sau đây là 3 cách dùng tổ hợp phím để chụp màn hình và lưu nhanh thành file ảnh .png vào Desktop:

1. Chụp nguyên màn hình
Command + Shift + 3,
rồi buông ra.

2. Chụp một vùng trên màn hình
Command + Shift + 4
, sau đó vẽ một hình chữ nhật khu vực cần chụp.

3. Chụp một thành phần giao diện (không dính nền, đẹp, chỉ dành cho Leopard)

Giữ Command + Shift + 4, trong khi giữ 3 phím đó, ta nhấn thêm phím Spacer bar (thanh dài), con chuột sẽ biến thành hình Camera, ta di chuyển đến thành phần nào (thí dụ cửa sổ, menu, icon, ...) thì sẽ chụp
thành phần đó và lưu lại thành file.

Build file .ipa with xCode 4.3

Để chuyển 1 file .app sang .ipa đầu tiên các bận cần có là 1 file .app, trong hướng dẫn mình sử dụng file Tuvi.app

1. Mở xcode len
2. Menu Window\Organizer



Wednesday, June 20, 2012

iPhone Tutorial: How to send In-App SMS


Officially, iPhone OS 4 is out of NDA and I can’t write a post on this. If you have been reading my blogs, you might already know how to send a in-app email Sending a in-app SMS is very similar to this, but with subtle differences.
Prior to iPhone OS 4, developers have to depend on
[[UIApplication sharedApplication] openURL: @"sms:12345678"];
So, Let’s get started.

Beginning Objective-C Programming


Table Of Contents
Chapter One: Introduction to ProgrammingChapter Two: If StatementsChapter Three: Switch StatementsChapter Four: LoopsChapter Five: FunctionsChapter Six: Object-Oriented ProgrammingChapter Seven: Introduction to Foundation and UIKitChapter Eight: Essential Foundation ClassesChapter Nine: How To Create Your Own ClassesChapter Ten: Extending Classes with CategoriesChapter Eleven: Protocols in Objective-CChapter Twelve: Key-Value Coding

[Object-C] Chapter 12: Key-Value Coding (KVC)


Another advanced technique is key value coding or KVC. This involves using a set of NSObject methods that can set or get property values based on their string representation. So, if a class has a name property you can get or set that value by using the dot notation in code or you can query the object with the string name to get or set the value.
This is an alternative to the typical way of working with properties that you can use in situations where you may not know the name of the property you will need at the time of writing the code. You may also use KVC to query arrays of objects or even arrays that are properties of an object.

[Object-C] Chapter 11: Protocols In Objective-C


A protocol is a way to require classes to implement a set of methods. We define a protocol much like a class or a category, it is essentially a list of methods. Protocols do not do anything themselves, they are a definition of a type of contract that we can require other classes to implement.
We call that adopting the protocol and we’ve seen this before. You may recall that the application delegate file that XCode created for use included this as part of the application delegate interface:
<UIApplicationDelegate>
This was required because we needed our class to act as an application delegate. This delegation pattern is implemented using protocols because we need a way to require a class to implement a set of methods in order for it to act as a delegate. The code above is how you indicate to the system that a class is adopting a protocol.

[Object-C] Chapter 10: Extending Classes with Categories


Much of the day to day work in object-oriented programming involves using classes that are already written. Sometimes we want our classes to do just a little bit more. That means they need more properties and methods and adding these entities changes the nature of the class. This is called sub-classing and we already covered how to do that.
There are times, however, when we want to extend the abilities of class but we don’t want to define a completely new class. You will encounter these situations more and more as you plunge into Objective-C programming. Perhaps more importantly, you will find examples of category use throughout the Mac and iOS programming examples written by Apple and other developers.
So, to extend a class without sub-classing you have the option of using categories. Let’s talk about how to do this.

[Object-C] Chapter Nine: How To Create Your Own Classes


At some point you will want to define your own classes to use in your app. So now let’s expand on the notion of object oriented programming by showing you how to implement your own custom classes. At this point you should be familiar with using existing objects in code; but you also need to be able to create your own types of objects.

Sub-Classes

One of the most common things that you will be doing with classes is something called sub-classing. As you can guess the iPhone has classes already in place to do things like present data tables, present windows and so on. Usually you will be creating your own object that inherits one of these preexisting objects and adding your own custom code to it. This is sub-classing.

[Object-C] Chapter Eight: Essential Foundation Classes


Now that we have a better handle on how object oriented programming works on iOS we should go over some of the key Foundation classes that you will use in your own apps. Like the name suggests, Foundation supports the key frameworks used in iOS development. Most of what you will be doing when building iOS apps comes from Foundation and will use Foundation classes.

Foundation Inheritance Hierarchy

Remember that classes can have an inheritance relationship with other classes. Although we did not mention it specifically we have already seen classes in Foundation that are in an inheritance relationship. The two classes that I am talking about are NSObject and NSStringNSString inherits from NSObject. You might also say that NSString is a kind of NSObject. Because of this relationship, NSString has all the properties and methods it needs to be and do what an object is.

[Object-C] Chapter Seven: Introduction To Foundation & UIKit


iOS developers use two key object oriented frameworks called Foundation and UIKitto do many of the most important programming tasks needed to make apps. Frameworks are collections of code that are shared by programmers that solve common problems. Foundation was built by engineers to solve common computing problems like using strings, managing collections of objects, connecting to the Internet, storing data, writing to the file system and much more. UIKit is the framework that is responsible for all the visual elements that you see on iOS apps like buttons, tables and tab bars.
I want to go over these frameworks with you in this chapter for two reasons. The first is that the best way to start learning object oriented programming is to see how objects are used in code. You need to learn how to instantiate objects from classes, manage memory with objects and how to use objects. Most of modern programming focuses on using code from frameworks like Foundation to develop software.

[Object-C ] Chapter Six: Object-Oriented Programming


Object oriented programming is a way of thinking about programming in terms of objects. An object in programming is like an object in the real world. That is, an object is something that you can describe and does things. Objects in the real world also have relationships to other objects. That is, an object in the real world may be made up or other objects, use other objects or it may be a variation of another object.
To help understand objects in programming, consider the example of a real world object like a car. You can describe a car as something that has four wheels, a color, model, make and so on. A car also does things like go forward, turn left and stop. Finally, a car is related to other objects in the world. A car is a type of vehicle (which itself is a kind of object), a car is made up on other objects (engine, wheels, stereo system) and a car is used by a person.
This way of describing and organizing things is natural for most of us. We tend to think of the world in terms of objects. In programming, objects are like the car example: an object’s attributes can be described and they can demonstrate behavior. Sometimes objects in programming actually correspond to objects in the real world. Programming objects also have relationships to other programming objects.

[Object-C] Chapter Five: Functions


A function in programming is a discreet area of code that is independent from the rest of the program. Functions are also called subroutines and as that name implies functions are a bit like small programs. Generally, functions may accept variables as inputs and a function may produce a value as an output.
Take a look at figure 1 to see what all the pieces of a function look like before we discuss each piece separately.
Figure 1: Anatomy of a Function

[Object-C] Chapter Four: Loops


Loops are used in programming when we want to repeat a similar task many times. Instead of just writing out each line of code we can use a loop to repeat code for a set number of times or until a condition is met. There are three types of loops that we will be discussing here: for loopwhile loopand do loop.
An example of something that you may want to do in programming that would be repetitive task is counting from 1 to 10. From what you learned in the past chapters you may try to count like this:
int count;
count = 0;
count = count + 1;
count = count + 1;
count = count + 1;
count = count + 1;
count = count + 1;
count = count + 1;
count = count + 1;
count = count + 1;
count = count + 1;
count = count + 1;
Clearly this task is very repetitive and with loops we can write it out in a much better way. Let’s see how to do the simple example above using each type of loop that we have available so far starting with the for loop.

[Object-C] Chapter Three: Switch Statements


switch statements are used when we want to execute different bits of code based on the value of an integer variable. While the if statement from the last chapter gave us two options (either the condition was met or it wasn’t),switch statements give us a way to conditionally execute code with more than two possibilities. Here is the general form that the switch statement takes.
int level = 0;

switch (level) {
     case 0:{
         //execute code when level == 0
         break;
     }
     case 1:{
         //execute code when level == 1
         break;
     }
     case 2:{
         //execute code when level == 2
         break;
     }
     default:{
         //execute code if level does not
         //meet any of the conditions above
         break;
     }
}

[Object-C] Chapter Two: If-Statements


If statements are used to execute code based on whether a condition is present in the state of the program. Simply put, an if statement is a way for us to tell a computer to do something if a condition is met and something else if the condition is not met. Below is the general form that an if statement takes.
BOOL condition = YES;
if(condition){
     //take action when condition is YES
}
else{
     //take action when condition is NO
}
The if statement above has three important components: the test to see if the condition is true, the code that will execute if the condition is true and the code that will execute if the condition is false.

[Object-C] Chapter One: Introduction to Programming


Programming is the process of giving instructions to a computer. Apps on your iPhone work because someone took the time to write instructions that have been packaged into an app that you download and use on your iPhone.
Here’s an example of how you would give instructions to an iPhone app. The code below will show us a alert that says Hello World:
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Alert View"
                                                    message:@"Hello World"
                                                   delegate:nil
                                          cancelButtonTitle:@"Ok"
                                          otherButtonTitles:nil];
[alertView show];
The code above will present an alert view to the user with the text Hello World. See figure 1.1 below for an example.
Figure 1.1 - Hello World
These instructions probably don’t make much sense to you yet but that’s ok – this book is all about how you can use instructions like this to get things done in your apps.

Monday, June 18, 2012

Integrate PhoneGap with Zxing for iOS - Barcode Scanner - Xcode 4

I spent a long time to config them. so tired, but now it run very good. It's work.

Step 1: 

Download Source PhoneGap at PhoneGap.com ( version 1.8.0 or higher )
after downloaded => install it and follow with introduction

Step 2: 

Download Source barcodescanner  at:
https://github.com/phonegap/phonegap-plugins/tree/master/iOS/BarcodeScanner

Friday, June 8, 2012

Learn Objective-C: Day 6


In today’s tutorial, you will learn about Categories and how to use them to extend the functionality of Cocoa-Touch classes. This is our final installment in the Learn Objective-C series, so you will also be provided with a quick recap on what we’ve covered so far and then look at what you can do to further your skills as an Objective-C or iPhone application developer.

Popular Posts