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