Private API: Upgrade check version Comparison

Source: Internet
Author: User

Private API, which allows the app to check the new version.

It's better to compare only numbers. How can we compare 1.0.1 and 1.0.2?

Business logic: when the user version is earlier than the latest version, an upgrade is prompted.

Both types are supported,CodeAs follows:

<? PHP  /*  ** Check the latest version.  */  Function Issecondbigger ( $ First , $ Second  ){  //  Pure numeric comparison      If ( Is_numeric ($ First )&& Is_numeric ( $ Second  )){  If ( $ Second > $ First  ){  Return   True  ;}  Else  {  Return   False ;}}  //  Comparison of x. x      If ( Stripos ( $ Second ,'.')! = False  ){  $ F = Explode ('.', $ First  );  $ S = Explode ('.',$ Second  );  $ Count = Count ( $ F  );  Foreach ( $ F   As   $ K => $ V  ){  //  For example, 1.0 to 2.0              If ( $ S [ $ K ]> $ V  ){  Return   True  ;}  //  It does not matter if the first digit is equal. The last digit must be greater than // For example, 1.0.5 to 1.0.8.              If (( $ Count = $ K + 1 )&&( $ S [ $ K ]> $ V )){  Return   True  ;}}}  Return   False  ;}  $ V = '1. 0.5 '; //  User version  $ Latest = '1. 0.8 '; //  Latest Version  $ Is_need_update = False ;  If (Issecondbigger ( $ V , $ Latest  )){  $ Is_need_update = True  ;}  Var_dump ( $ Is_need_update  ); ?>

 

API: http://api.example.com/latest? App_id = 1 & V = 1.0.2 & WLT = ZH-Hans

Input:

App_id: the private API allocates IDs for multiple apps of the company, such as andriod, iPhone, iPad, and PC.

V: Version Number installed by the user

WLT: Text code, such as en_us, ZH-HANT, zh_cn for iOS, zh_cn for Android, zh_cn, ZH, and zh_tw, which are mapped by the backend, directly connect the app to the system value.

References:

Http://developer.android.com/reference/java/util/Locale.html

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.