< go > go to iOS from Java First project summary

Source: Internet
Author: User
Tags sqlite database

A summary of the first project from Java to iOS Read Catalogue
    • 0. Preface
    • 1. Project Introduction
    • 2. Third-party open source libraries used by the project
    • 3. Introduction to Tools and plugins
    • 4. Integration of the League of Friends
    • 5. Instant Messaging
    • 6. Project Summary
0. Preface

In December 14, I moved from the Web development team to the Mobile Development group, and my Java 2.5 experience became the Object-c 0 experience. January 2015 launched a new mobile project, after years because of personnel changes, their own from the auxiliary development into the "core" development, the current project is nearing the end, summarized below, I hope that some people can help, but also hope that the iOS Daniel guidance

Back to top 1. Introduction of the Project

The project belongs to a community-based software that includes groups/posts, videos, articles, recommended searches, instant messaging, friends, third-party login/sharing, push, etc., covering the basic features of popular apps

Back to top 2. Third-party open source libraries for project use

http://github.ibireme.com/github/list/ios/collated the more commonly used iOS third-party components, as well as the statistics on GitHub

The project uses Cocoapods (like Maven in Java) to manage commonly used third-party libraries, some special separate references, and the following are some of the more useful

1.AFNetworking

Currently the recommended iOS network request component, the default network request is asynchronous, through the block callback to the return data processing.

It is important to note that the contenttype requirements returned by Afnetworking for network requests are strict, such as that only Application/json return is supported by default. Therefore, you may need to add support for test/html return, otherwise the backend may not be able to get the returned data.

The other is the file upload, it is recommended to use the second

?
123  [formData appendPartWithFormData: name:];  [formData appendPartWithFileData: name: fileName: mimeType:];

The first one only needs to pass in the table sole name and the file stream, the source code is also based on the file stream to obtain the corresponding file name and type and then call the second method. But the landlord encountered the use of the first method, submitted after the background to determine non-file upload, unable to obtain file stream. Also, if the background is based on the file suffix file type, then the first kind is not available.

The afnetworking is asynchronous, or you can use a synchronous network request method.

2.FMDB

SQLite database operation has been encapsulated, for the background development for many years, I have no problem, look at it to know how to use

3.MBProgressHUD

It is also a common component of iOS projects to show the transition effect, compare network requests before displaying loding, and network end hidden loading. Recommended encapsulation in Baseviewcontroller, all Viewcontroller inheritance can be used

4.MJRefresh

This is a podcast Li Mingjie Teacher's work, his OC basis is to watch his video half a week on the basic win. Mjrefresh is mainly used for refreshing operations, providing common refresh operations, as well as refreshing animations, which are very useful. It is recommended that you encapsulate the method in Baseviewcontroller so that when you modify the refresh operation, you only need to change one copy. (previously used by the old version of Mjrefresh, only support normal refresh, not support animation, later to the update found that the change is very large, the old method has not been recommended, so it is better to use the package base class, but also easy to modify)

5.SDWebImage

This is also the most commonly used iOS component, the user loads the network picture, can be cached locally. Presumably, after the first load, the file name is cached locally based on URL encryption, and if the picture is loaded again, it is loaded directly from the local page. It's easier to use. Here also share a problem encountered,

Load a small map from the network, then a small image as a booth map, and then load a large image from the network

?
12345  [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, can easily set the bottom menu text picture, click Effect, Little red dot hint and so on

7.Toast

Similar to the Android toast hint effect, encapsulated in Baseviewcontroller, where needed to prompt

8.XMPPFramework

iOS's only XMPP class library, the author added the XEP-0198 protocol support (stream management for XMPP disconnection) last August, but cannot download to the latest version when it is updated via pod, perhaps 0198 is not perfect enough to be a full version.

9.TPKeyboardAvoiding

User keyboard Popup automatically calculates height for screen scrolling operation

10.AMR

Do instant Messaging audio processing, currently our Instant Messaging uses a recording file that is M4A for easy web-side audio playback

11.TQRichTextView

Used to display Rich text view controls, emoticons for instant messaging, and Rich text display of resource reviews

12.CSGrowingTextView

Use as an Instant Messenger text box and comment text box to display multiple lines of input

13.MJExtension

Li Mingjie is also the work of the teacher, for the use of JSON to model, a bit similar to the Java Google Gson. Conversion efficiency is said to be very high, the use is relatively simple, as long as the front and back of the agreement, JSON directly into the model. An iOS friend who has worked for years says that a project is primarily about managing the model layer, and he recommends mantle. MJ, however, is more lightweight and easier to use.

Back to top 3. Introduction of tools and plugins
    1. Xcode

      The official tool for iOS development, there is no other choice. Some of the features do do pretty well, like Stroyboard's drag-and-drop event bindings. Uncomfortable place is no code formatting, another click Method, may run to another class!! In addition, the left side of the directory will not automatically change, to locate the corresponding file, need command+shift+j

    2. SimPholders2

      You can quickly find the simulator corresponding to the sandbox directory, the right top toolbar after launch has a button similar to close buttons, showing several recent applications, click to enter the corresponding sandbox directory

    3. Vvdocumenter-xcode

      Xcode tool,///Generate note template, Xcode This feature does not give integration, alas

The other basic is not introduced, and some are not very useful. SVN can use the Cornerstone,git can use Sourcetree,sqlite can use the SQLite Professional (just a fee, free to view only), you can also use the Firefox browser SQLite plugin.

Back to top 4. Integration of the League of Friends

Friends Alliance, provides a one-stop solution for apps and applications. The company last mobile project used to the Friend Alliance push service, this project, also used the sharing, third-party login function, oneself also participated in the relevant integration. Friends of the league's developer documentation is relatively complete, encounter problems can contact customer service or to the Friends of the Forum to find solutions.

1. About push

iOS push is divided into local push and remote push, local push refers to the local pop-up information, the other is remote push, when the app does not start, you can also receive the relevant push information. Our project is not using local push, it is using the Friend Alliance remote push. Includes messages (chats) and notifications (user information notifications). Users in the chat process, the phone in addition to send instant messaging, but also call the background interface, send Friends League push. Another user's posts, comments, concerns, likes and so on will be transferred from the background to the push of the Union.

Friends of the League (and Friends of the Alliance address) including unicast, multicast, and broadcast, which broadcast a limit of 3 times a day, you can and friends to increase the number of applications, and other non-limited number of times, the current rate of unicast is very fast. Using Friends League push, you need to create a new two push certificate in the Apple Developer account, submitted to friends League (Friends of the league has detailed documentation, can be consulted). Can be in the league backstage, the test equipment Devicetoken added to the friends of the push back backstage (need 64 tokens, need to calculate through the method, directly in Xcode or ituns to get token not), from the Friends of the background to launch push.

Push the approximate process is that the mobile phone in the first launch of the app when the push service, mobile phone in the launch of the app, registered Friends of the Alliance service, while the Devicetoken submitted to their own backstage, backstage in the need to hold the devicetoken to adjust the push interface, Friends of the alliance to launch the Apple push service, so that the corresponding device received remote push information.

Our push message, custom message body and XMPP message body, in addition to the Friend Alliance remote push, XMPP will also send a copy, two messages local only one copy, which received first processing which.

2. About third-party login and sharing

This piece is in the social sharing of friends union, inside also improved the more comprehensive document. Third parties are advised to share without their own special design, you can make the default sharing module (our project's share module has its own design, including the collection, so the entire block requires a custom write UI and write sharing code). About Friends of the third party login and sharing needs attention, QQ and login sharing, all need to install the application on the phone, so need special treatment, determine whether the phone installs the application, otherwise hide related icons, this piece of the Alliance of Friends of the SDK has the relevant judgment method (should be friends of the league integrated QQ and, QQ and SDK provide a method of judging).

Third-party login sharing requires a developer account to be registered with the relevant platform. A third-party login with a developer account (not a subscription number) will need to be paid to activate the function and can be shared with a circle of friends. QQ developer account can support QQ and QQ space sharing (QQ microblogging seems to need Weibo developer account). Sina Weibo needs Weibo developer account. QQ seems to need to add a test account to the QQ developer account friend to test, Weibo is similar.

Third party login himself encountered the QQ prompt is not the latest version of the text, in the Friends of the Forum found a solution.

Third-party login, our project integrates QQ, Sina Weibo login. Three platforms can obtain the user's Screen_name (user name), in addition to obtain the corresponding platform unique ID, which QQ and are OpenID, Sina is the UserID.

Third party sharing, documentation provides sharing pictures, videos, voice. If you are sharing URLs, you need to set up a shared address for the corresponding platform, refer to the solution, such as

?
1234 &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; [ Umsocialdata defaultdata].extconfig.qqdata.url = shareurl; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; [UMSOCIALDATA&NBSP;DEFAULTDATA].EXTCONFIG.QZONEDATA.URL&NBSP;=&NBSP;SHAREURL; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; [UMSOCIALDATA&NBSP;DEFAULTDATA].EXTCONFIG.WECHATSESSIONDATA.URL&NBSP;=&NBSP;SHAREURL; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; [UMSOCIALDATA&NBSP;DEFAULTDATA].EXTCONFIG.WECHATTIMELINEDATA.URL&NBSP;=&NBSP;SHAREURL;

In addition to share to QQ space, must develop a picture, otherwise sharing unsuccessful.

Third party sharing recommendations encapsulated into a class, our project is a few detail pages are shared, comments, reports, collections, like and other features. Encapsulated in a basedetailviewcontroller, the related page inherits, and the corresponding resource type is passed in, and only one copy of the code is maintained.

Back to top 5. Instant Messaging

There are third-party solutions on the instant communication networks, such as the ring letter, the cloud and so on. We are our own XMPP server, the server used by the Tigase, previously written related to the blog, their own last year also did the corresponding Webim. The previous time looked at the ring letter Webim SDK, the use is also the Strophe JS class Library, the related implementation is similar to ours, but the implementation of XMPP will encounter a lot of problems, such as lost messages. So if you want to implement IM more quickly, we recommend using a third-party solution.

The lost message on the mobile side is probably like this. A and B communication, a sent a message to the server, the server sent to B, but B network is not good to drop, and the server did not know that B exited (b Normal exit will be sent to the server notification), so the message was lost. XMPP has the XEP-0184 protocol (message receipt), A to B message, the body of a line of code, request message receipts, when B received a message sent a receipt, proof I received. Later XMPP has a xep-0198 protocol (flow Management), fast heavy chain after disconnection, while judging a certain time to receive the message, write the message offline message, reduce the loss of messages. However, there may be complex network conditions, coupled with a variety of uncertainties, but also the problem of lost messages. So at present the more reliable method is to save all the chat record, from the mobile phone side according to the time point to the database pull messages, as long as the message will not be lost.

The Instant Messenger module has been changed and is also a reference to some of the previous developers ' suggestions. For example, when the user home returned, disconnected XMPP connection (iOS into the background, only 5 seconds of processing time, the special method can be extended to 10 minutes, if the memory is not enough, the app will be killed at any time). So when you go back home, you disconnect and then connect to the app. At the same time the use of the state, there is heartbeat detection, determine whether to stay connected. User Chat In addition to sending XMPP messages, but also call remote push (push set expiration time, avoid special circumstances, push delay, chat ended before receiving push).

About Push, iOS has appdelage in two ways, one is to use in the receive push, will not prompt, will directly process the push information. In addition, the program is non-use status, received push, will be prompted, click Push to enter the application, call the corresponding method to get the corresponding push message (need to note, click Push Launch app, view has not been loaded, the message can not be processed immediately).

So considering the peculiarities of iOS, the method of both XMPP and remote push is taken, and the custom message body and the XMPP message body are pushed in the same way as the message is handled. One is to solve the push receive when the iOS app is not started, and the other is to resolve the problem of XMPP drop message.

Android side because it is the real background, so you can keep running in the background, regardless of whether the Android received the XMPP message or the friend League push, are processing themselves, and then play a local push (there are drawbacks, if the Android program killed, you can not accept messages and push). iOS because the background is not controllable, so push the use of remote push, into the application to receive XMPP all offline messages (there may be problems, such as a large number of users, friends of the Union push can ensure timely). Of course, most of the normal situation, in the use of the process, the real-time received XMPP messages or remote push, directly prompted. As long as the user to ensure that the data consistency is OK (so QQ and hard to see AH).

Based on the feedback from the test, the iOS app has a somewhat improved messaging situation than the previous application. Further observation of the specific situation.

Our instant messaging also includes voice and images, HTTP solutions, and XMPP supports binary transmissions, but no one is expected to use them. The specific is to upload attachments to the attachment server to the address of the attachment server, and then encapsulated to the message body. When the receiving party receives the message parsing, it gets the corresponding resource from the attachment server and loads it locally. At the same time, some real-time operation such as shielding, unblock, etc. will also be sent XMPP, the first time both sides updated status.

Back to top 6. Project Summary

The project is nearing its end, and it will be online in less than half a month. I am the main person in charge of the project. Early in the project, iOS and Android have more than a week of preparation and framework, in addition, I based on the page prototype, define the interface document development plan, coordinated development. Perhaps everyone project experience is not many, the framework and interface will be a bit more or less, as the experience gradually accumulated will be more and more good. For a summary of iOS:

1. When the frame is built, consider the implementation of each function point in the app. Design the relevant file directory, and encapsulate the related class files.

2. Packaging and finishing related methods, such as Baseviewcontroller include, basic UI, top navigation bar, left button, right button, title, related click event, show/Hide loading, network request failed unified processing method, pull/dropdown refresh bindings, refresh Show/Hide. Analyze the function of the same module in the project, package the corresponding operation, and maintain one copy of the same function code.

3. Consider the refresh mechanism, such as a page into the B page, b after the update, the return to a page after the refresh, if the use of block method, can be unified design. Or the data refresh between multiple pages, using the notification method (KVO), to update the operation. Try to develop the stage and solve the problems that may arise in advance.

4. Determine whether the relevant page statistics, such as Jiayou's page statistics, need to set the relevant view of the Viewwillappear and Viewwilldisappear ()

After initializing view and data requests in 5.ViewController, refresh view detach, encapsulate and organize the related operations before and after the network request, consider the drop-down refresh page and pull-up loading more related data processing and view display. Network-aware data caching and non-network cache data loading

6. Jump ahead of the relevant page, and code decoupling, need to continuously optimize and refactor the code. If you find a problem or have a better solution, modify it as early as possible, avoid tinkering, and code is not easy to maintain and extend later. Under acceptable circumstances, some system can be sacrificed to keep logic simple and easy to maintain.

7. When calculating coordinates from code write view, refer to the coordinates and width of the previous element as much as possible, so that when an element position or width is changed, the other elements can basically change as they occur.

8. Data processing can be placed on server-side processing by the server-side processing, the front desk is no brain display

9. Consider the compatibility of the program, the values of the 32-bit and 64-bit variables are different, note the value of the cross-border problem. Note the memory issues of the program, and the memory changes during use

< go > go to iOS from Java First project summary

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.