How the iOS platform enables cross-platform communication

Source: Internet
Author: User
Tags coding standards

Apple mobile phone led the fiery iOS, a lot of developers in the development of the iOS platform, I believe you have also used QQ voice video dialogue function, but do not know whether you have tried to develop an iOS platform based on audio and video instant messaging applications, this application must be able to cross-platform. Now there are two ways to use audio and video calls from iOS to other platforms.


The first is the use of a cross-platform audio and video communication platform, which is not a professional technical personnel can also do, the following first introduction: only three conditions:


1, mobile phone has internet connection;


2, have anychat for IOS SDK;


3, the other PC or mobile phone has the above conditions.


Anychat Audio and video interactive development platform is a cross-platform of instant messaging solutions, based on advanced H. S video coding standards, AAC audio coding standards and peer-to technology, characterized by: high-quality, wide adaptability, distributed, modular. The ANYCHATSDK is divided into the Client SDK and the Server SDK, where the client SDK is used for voice, video interaction and other client-related functions, while the server SDK mainly implements the logic control of the business layer and the interconnection with the third-party platform. Both the Client SDK and the Server SDK support C + +, C #, and VB. NET, and Delphi and other development languages.


The Anychat for iphone is based on iOS 4.3 and supports devices such as the iphone 3G, iphone 3GS, and IPhone4, while also supporting the ipad, iPad2 devices, and OBJECTIVE-C interfaces. The Anychat for iphone can be connected to the anychat of other platforms, connect to the same server program, and the SDK for the server can refer to the Anychat Platform Core SDK Development Kit.


Talking about Anychat, cross-platform with support for high-definition, peer-to advanced technology is the leading domestic, last week is a breakthrough in the perfect solution to solve the echo problem on Android devices, Anychat will also release a new version this month. In mobile applications, Anychat released the first program to run on the web last year, video chat with Anychat mobile devices on the same platform, and experience real-time audio and video capabilities in mobile Web applications.


Instant Video communication is becoming a mainstream service, but the problem of fragmentation of mobile devices is always bothering developers. But with the anychat for IOS SDK, developers can easily integrate instant Video communications into their applications through an open API calling function, dramatically reducing project time and eliminating the need to spend a lot of money on test work.


The second is to use the API interface to develop their own audio and video software

Want to achieve audio and video communication under the iOS platform, the quickest way is to find open source projects or call other companies packaged API, the next small to introduce a good SDK package to everyone, has been uploaded to the 51CTO resources above, It's safe to use (Audio Instant Messaging app development on iOS) Here are some ways to call the API interface, and we can communicate with each other.


View Sourceprint?


01.//Initialization SDK


02.public native int initsdk (int osver, int flags);


03.//connecting to a server


04.public native int Connect (String serverip, int port);


05.//Login System


06.public native int Login (string username, string password);


07.//Enter the room (room ID)


08.public native int enterroom (int roomid, String password);


09.//Enter the room (room name)


10.public native int Enterroomex (string roomname, string password);


11.//exit the room


12.public native int leaveroom (int roomid);


13.//Setting the video display location


14.public native int setvideopos (int userid, surface surface, int lef,


15.int top, int right, int bottom);


16./**


17.* function: Set the video display location, or refresh the video display return value: 0 indicates success, otherwise it is an error code


18.* Parameters:


19.* userid User ID


20.* Surface Video Display interface, Android client only needs to provide Surfaceview control, the kernel will automatically display the video on the control


21.* Lef,top,right,bottom Video Display location information


22.*/


23.//Log Off Login


24.public native int Logout ();


25.//Releasing Resources


26.public native int Release ();


First, the initialization of the SDK

Initializing the SDK is the first thing you need to do to set up some behavior for the SDK, including setting the corresponding callback function. The code is as follows:


View Sourceprint?


01.//Initialization SDK


02.private void Initialsdk () {


03.if (Anychat = = null) {


04.anychat = new Anychatcoresdk ();


05.//Setting the basic event callback function


06.anychat. Setbaseevent (this);


07.if (Configentity.usearmv6lib! = 0)


08.anychat. Setsdkoptionint (Anychatdefine.


09.brac_so_coresdk_usearmv6lib, 1); Using the ARMV6 instruction set


10.anychat.   INITSDK (Android.os.Build.VERSION.SDK_INT, 0); One parameter to initialize the SDK is the Android API version


11.bNeedRelease = true;


12.}


13.}


Second, login system

After the initialization of the SDK is complete, it can be implemented to connect the server, verify user identity, user login and so on.


View Sourceprint?


1.//connecting to a server


2.anychat. Connect ("211.155.25.90", 8906);


3.//Login System


4.anychat. Login ("Android", "");


Both the connection server and the logon system are asynchronous processes that return immediately after the call. In the callback function, according to the return code to determine whether the server connection success and logon success.

Third, enter the room

After the successful login can enter the corresponding room, only in the same room users can do audio and video communication. The code is as follows

1. Enter the room


View Sourceprint?


1.//, enter room 1th.


2.anychat. Enterroom (1, "");


After entering the room, the system will send the room online users to the client, only in the same room users can do audio and video exchange, text chat, file transfer and so on. When a new user enters a room or a user goes offline, an asynchronous message is triggered to notify the upper-level app to change state.

2. Text Chat

Once you have successfully entered the room, you can call the API interface to send a text chat message to the specified user or to all online users in the room.


View Sourceprint?


1.//Sending text chat messages


2.String message = Messageedittext.gettext (). toString ();


3.anychat. Sendtextmessage ( -1, 0,message);


Other users receive a text chat message that triggers the corresponding callback function and displays the chat message on the interface.

3. Request audio and video from other users


View Sourceprint?


1.//request each other's video stream


2.anychat. Usercameracontrol (UserID, 1);


3.//requesting the other's audio stream


4.anychat. Userspeakcontrol (UserID, 1);


4. Display and playback of audio and video


View Sourceprint?


01.//determine if the remote user video is turned on


02.if (!bothervideoopened) {


03.if (Anychat. Getcamerastate (UserID) = = 2


04.&& Anychat. Getuservideowidth (userID)! = 0) {


05.SurfaceHolder holder = Otherview.getholder (); Get the Surfaceview control


06.holder.setformat (pixelformat.rgb_565); Set display format


07.holder.setfixedsize (Anychat. Getuservideowidth (UserID),


08.anychat.    Getuservideoheight (UserID)); Set video display width to height


09.Surface s = holder.getsurface (); Get video footage


10.anychat.     Setvideopos (UserID, s, 0, 0, 0, 0); Call API to display video screen


11.bOtherVideoOpened = true;


12.}


13.}


14.//determine if the local video is turned on


15.if (!bselfvideoopened) {


16.if (Anychat. Getcamerastate (-1) = = 2


17.&& Anychat. Getuservideowidth (-1)! = 0) {


18.SurfaceHolder holder = Myview.getholder (); Get the Surfaceview control


19.holder.setformat (pixelformat.rgb_565); Set display format


20.holder.setfixedsize (Anychat. Getuservideowidth (-1),


21.anychat.        Getuservideoheight (-1)); Set video display width to height


22.Surface s = holder.getsurface (); Get video footage


23.anychat.         Setvideopos ( -1, s, 0, 0, 0, 0); Call API to display video screen


24.bSelfVideoOpened = true;


25.}


26.}


Android program, when receiving the user's media stream data, the Android client only need to provide a Surfaceview control, the kernel automatically displays the video stream data on the control and plays the sound.

Iv. release of resources

With the previous connection server, login system, enter the room corresponding to the departure room, logout system, release resources. The code is as follows: Www.it165.net


View Sourceprint?


1.protected void OnDestroy () {


2.//left the room.


3.anychat. Leaveroom (-1);


4.//Log Off Login


5.anychat. Logout ();


6.//Release resource Close SDK no longer returns to login interface


7.anychat. Release ();


8.}


You can enter the room after you leave the room, but the SDK will no longer work after logging off and releasing resources. The resource can be freed at the end of the activity life cycle and the program exits.


How the iOS platform enables cross-platform communication

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.