Third-party open-source libraries commonly used in iOS Projects

Source: Internet
Author: User

Third-party open-source libraries commonly used in iOS Projects

1. Third-party open-source libraries used by the Project

The project uses CocoaPods (similar to maven in java) to manage common third-party libraries. Some special references are provided separately. The following describes some useful examples.

(1) AFNetworking

Currently, the recommended iOS network request component is asynchronous by default. It processes the returned data through block callback.

It should be noted that AFNetworking has strict requirements on the ContentType returned by the server. By default, only application/json return is supported. Therefore, you may need to add support for text/html returned, or you may not be able to obtain the returned data.

The other is File Upload. The second type is recommended here:

 
[FormData appendPartWithFormData: name:];
[FormData appendPartWithFileData: name: fileName: mimeType:];
First, you only need to input the form name and file stream. The source code also obtains the corresponding file name and file type based on the file stream, and then calls the second method. However, the landlord encountered the first method. After the submission, the background determined that the file was not uploaded and the file stream could not be obtained. In addition, if the backend is based on the file suffix file type, the first type cannot be used.

AFNetworking is asynchronous. You can also use synchronous network request methods.

(2). FMDB

The sqlite database operations are encapsulated, And the demo is relatively simple.

(3). MBProgressHUD

It is also a commonly used component in iOS projects to display the transition effect. For example, loading is displayed before a network request, and loading is hidden at the end of the network. We recommend that you encapsulate it in BaseViewController, so that all ViewController inheritance can be used.

(4). MJRefresh

This is the work of Dr. Yan Jie of Chuanzhi podcast. His oc base is that he basically won the video for half a weekend. MJRefresh is mainly used for Refresh operations. It provides common refresh operations and refresh animations, which are useful. We recommend that you encapsulate the method in BaseViewController. In this way, you only need to modify the refresh operation. (The old version of MJRefresh used previously only supports normal refresh and does not support animation. Later, the version changes a lot and the old method is no longer recommended, therefore, it is better to encapsulate the base class for later modification)

(5). SDWebImage

It is also the most commonly used component in iOS. Users can load network images and cache them locally. In general, after the first loading, the file name will be cached locally based on url encryption. If the image is loaded again, it will be directly loaded from the local. It is easy to use. Here we also share a problem. First, we need to attach a small image from the network, then use the small image as the occupied bitmap, and then load a large image from the network.

 
[ImageView sd_setImageWithURL: [NSURL URLWithString: imageURLString] placeholderImage: DefaultPostPic];
[ImageView sd_setImageWithURL: [NSURL URLWithString: _ bigImageURLStringArray [I] placeholderImage: imageView. image options: SDWebImageDelayPlaceholder completed: ^ (UIImage * image, NSError * error, SDImageCacheType cacheType, NSURL * imageURL ){
}];
(6). RDVTabBarController

A TabBar component allows you to easily set text images, click effects, and red dots at the bottom menu.

(7). Toast

Similar to the toast prompt effect of android, It is encapsulated in BaseViewController and prompted where necessary.

(8). XMPPFramework

The only xmpp class library in iOS, the author added xep-0198 protocol support (Stream Management for xmpp reconnection) in last August, but when updated through the pod, cannot be downloaded to the latest version, maybe 0198 is not complete yet and cannot be used as the official version.

(9). TPKeyboardAvoiding

The height is automatically calculated on the keyboard to scroll the screen.

(10). AMR

For instant messaging audio processing, the current recording file used for instant messaging is m4a, which is convenient for web-side audio playback.

(11). TQRichTextView

It is used for Rich Text View control display, instant messaging expression display, and resource comment rich text display.

(12). CSGrowingTextView

Used as the instant messaging text box and comment text box to display multiple lines of input.

(13). MJExtension

It is also the work of instructor Yan Jie, which is used for converting json to model. It is somewhat similar to Google's Gson in java. The conversion efficiency is also said to be very high, and it is relatively simple to use. json is directly converted into a model as long as the previous and background conventions are agreed. An iOS friend who has been working for many years said that a project mainly manages the model layer and he recommends Mantle. However, MJ is more lightweight and easier to use.

3. Introduction to tools and plug-ins

Xcode

There is no other choice for official tools developed for iOS. Some functions are really handsome, such as the drag-and-drop event binding of StroyBoard. The unpleasant thing is that there is no code formatting. In addition, the clicking method may be in another class !! In addition, the directory on the Left does not change automatically. To locate the corresponding file, you need command + shift + j.

SimPholders2

You can quickly find the sandbox directory corresponding to the simulator. After the startup, a button similar to the close button is displayed on the top toolbar on the right side. The most recent applications are displayed. click the button to enter the corresponding sandbox directory.

Vv1_enter-Xcode

Xcode tool, // generates Annotation Templates. xcode is not integrated.

You don't need to introduce other basics, and some of them are not easy to use. SVN can use Cornerstone, Git can use SourceTree, sqlite can use SQLite Professional (but it is charged and can only be viewed for free), and Firefox sqlite plug-in can also be used.

4. Integration with umeng

Umeng provides an all-in-one solution for apps and applications. In the last mobile project of the company, umeng's push service was used. In this project, sharing and third-party login functions were also used. Umeng's developer documentation is comprehensive. If you have any problems, contact our Customer Service or go to umeng's forum to find a solution.

(1). About push

IOS push can be divided into local push and remote push. Local push refers to the local pop-up information, and remote push refers to the push information that can be received when the application is not started. Our project does not use local push, and umeng remote push is used. Including messages (Chats) and notifications (user information notifications. In addition to sending instant messaging, the mobile phone also calls the background interface to send umeng push messages during the chat process. In addition, user posts, comments, concerns, and likes will be pushed by umeng in the background.

Umeng push (another domain name) includes unicast, multicasting, and broadcast. The number of broadcasts is limited to three times a day. You can apply to umeng to increase the number of broadcasts, currently, the unicast speed is quite fast. To use umeng push, you need to create two new push certificates in the Apple developer account and submit them to umeng (umeng has detailed documentation for reference ). You can add the deviceToken of the test device to the backend of umeng push and initiate the push from umeng backend. (64-bit token is required and calculation is required through the method. It cannot be obtained directly in xcode or ituns)

The general process of pushing is that when the mobile phone starts the PUSH Service for the first time, the mobile phone registers the umeng service when starting the app, and submits the deviceToken to its own background, the backend can call the push interface of umeng with deviceToken as needed, and umeng then initiates the PUSH Service of apple, so that the corresponding device receives the remote push information.

(2). Third-party login and sharing

This part is shared by umeng's social community, which provides comprehensive documentation. We recommend that you use umeng's default sharing module (the sharing module of our project is designed by yourself, including the favorites module, therefore, you need to customize the UI and share code for the entire block ). When you need to pay attention to third-party login and sharing of umeng, QQ and login and sharing both require installation of applications on the mobile phone, and the appstore review will be stuck. Therefore, you need to determine whether the app is installed on your mobile phone, hide the icons without app installation. This umeng sdk already has related judgment methods (umeng integrated QQ and sdk, and QQ and sdk provided judgment methods ).

Third-party logon and sharing require you to register a developer account with the relevant platform. A developer account (note that it is not a subscription number) must pay for a third-party login. It can be shared with friends. QQ developer accounts support QQ and QQ space sharing (QQ Weibo seems to require Weibo developer accounts ). Sina Weibo requires the Weibo developer account. In the QQ sharing and development phase, you need to add the test account to a friend of the developer account before testing. Weibo is similar.

When a third party logged on to the website, he encountered a QQ prompt that the text was not the latest version. He found a solution in the umeng forum.

Third-party login, our project integrates QQ, Sina Weibo login. The three platforms can obtain the user's screen_name (User Name) and the unique id of the corresponding platform, where QQ and both are openid and Sina are userid.

Third-party sharing. The document provides sharing images, videos, and voice. For a sharing url, you need to set the sharing address of the corresponding platform. For more information, see solution. For example:

 
[UMSocialData defaultData]. extConfig. qqData. url = Invalid url;
[UMSocialData defaultData]. extConfig. qzoneData. url = Invalid url;
[UMSocialData defaultData]. extConfig. wechatSessionData. url = signed url;
[UMSocialData defaultData]. extConfig. wechatTimelineData. url = signed url;
In addition, you must specify an image for sharing to the QQ space. Otherwise, the image cannot be shared successfully.

Third-party sharing suggestions are encapsulated into a class. Our project has several details pages including sharing, commenting, reporting, adding to favorites, and thumb ups. Encapsulated in a BaseDetailViewController, the relevant page inherits, and the corresponding resource type is passed in. Only one piece of code is maintained.

5. Instant Messaging

There are third-party solutions on the instant messaging network, such as huanxin and rongyun. We built our own xmpp server and used tigase on the server. We have previously written related blogs and developed webim last year. Some time ago I read webim sdk and used strophe js class library. The implementation is similar to ours, but I encountered many problems when I set up xmpp, such as message loss! Therefore, if you want to quickly implement im, we recommend using a third-party solution.

The message loss on the Mobile End is probably like this. A communicates with B. A sends A message to the server, and the server sends A message to B. However, the B network cannot be disconnected, the server does not know that B has exited (B will send a deprecation notification to the server if B Exits normally), so the message is lost. XMPP has A xep-0184 protocol (Message receipt), A sends A message to B, the message body with A line of code (requires message receipt), when B receives the message to send A receipt, prove that I received. Later, XMPP has a xep-0198 protocol (Stream Management), fast heavy chain after disconnection, at the same time to determine a certain time to receive the message, the message is written offline message, reduce message loss. However, the network may be complex, and various uncertainties may cause message loss. At present, a more reliable method is to store all chat records and pull messages from the database on the mobile phone end based on the time point. messages sent by others will not be lost.

This time, the instant messaging module was modified, and some suggestions from previous developers were also referenced. For example, when a user returns home, the xmpp connection is disconnected (the processing time is only 5 seconds after iOS enters the background, and the special method can be extended to 10 minutes. If the memory is not enough, the application is killed at any time ). Therefore, when the returned home is disconnected, the application is connected again. At the same time, the application uses a heartbeat check to determine whether the connection is retained.

Considering the particularity of iOS, we adopt the xmpp and remote push methods. The custom message body pushed is the same as the xmpp message body, and the message processing method is the same. When users send xmpp messages through chat, they also call our message push interface to call umeng push (push can set the expiration time to avoid special situations, push delay, and push is received only after the chat ends ). One is to solve the push and receive issues when the iOS application is not started, and the other is to solve the xmpp message loss problem.

For push, there are two methods in AppDelage. One is to receive push in use and will directly process push information without prompting. In addition, if the application is not in use, a prompt will be displayed when you receive the PUSH message. You can click the PUSH message to enter the application and obtain the PUSH message for this push message (note that, when you click push to start the application, the view is not loaded and the message cannot be processed immediately ).

Because the android end is a real background, it can always run in the background. You can handle the xmpp message or umeng push by yourself, and then play a local push by yourself (there are also drawbacks, if the android program is killed, messages and pushing cannot be received ). Because the iOS end is not controllable in the background, the push uses remote push to connect to the application xmpp and receive all offline messages (it is not guaranteed that umeng push can be timely ). Of course, most of them are normal. If the network condition is good, xmpp messages or remote push are received in real time. We are not QQ and we only need to ensure that the data we see can be consistent (So QQ and diao ).

According to the test feedback, the message loss rate of the iOS app is somewhat higher than that of the previous app. The specific situation is further observed.

Our instant messaging also includes voice and images, using http solutions (xmpp also supports binary transmission, but it is estimated that no one uses it ). The specific process is to first upload the attachment to the attachment server to get the address of the attachment server, and then encapsulate it into the message body. When receiving the message resolution, the receiver obtains the corresponding resources from the attachment server and loads them to the local device. At the same time, some real-time operations such as blocking and unblocking will also issue xmpp, and both parties will update the status immediately.

Related Article

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.