Just My Life & My Work

Posts tagged ‘api’

[Flutter] HttpClient

現在手機主要功能就是拿來上網,所以任何 App 基本上都會需要透過網路存取資料,此時 Flutter 可以怎麼操作呢?使用內建 io package 就可搞定!🙃

我特地寫一個近年來很夯的比特幣查價系統,可以隨時查看多家交易平台上比特幣的實價,也許還可以進一步變成「搬磚」工具!

只要點擊藍色按鈕,就能即時取得多家交易所比特幣的實價。

(繼續閱讀…)

呼叫 API 的 URL 過長問題

最近在整合 API,需要附加大量的參數,使用 Get 方式呼叫,發生:

Request failed: requested URL too long (414)

搜尋一下問題,原因如下:

Two options to resolve the problem for 414 response code:

  1. By POST request: Convert query string to json object and sent to API request with POST
  2. By GET request: Max length of request is depend on sever side as well as client side. Most webserver have limit 8k which is configurable. On the client side the different browser has different limit. The browser IE and Safari limit to 2k, Opera 4k and Firefox 8k. means the max length for the GET request is 8k and min request length is 2k.
    If exceed the request max length then the request truncated outside the limit by web server or browser without any warning. Some server truncated request data but the some server reject it because of data lose and they will return with response code 414.

最後我改成 Post 方式呼叫,就再也沒有此問題!😃

iOS 回傳

Error Domain=com.alamofire.error.serialization.response Code=-1011 “Request failed: requested URL too long (414)" UserInfo={NSLocalizedDescription=Request failed: requested URL too long (414), 

Chrome 回傳

Request-URI Too Large
The requested URL’s length exceeds the capacity limit for this server.
Apache/2.2.15 (CentOS) Server at upload.tintint.com Port 443

參考:414 (Request-URI Too Long)

透過 Performance 看優化成果

人總是會不斷地成長,若沒有成長就會感到不開心,是真的吧?🤪

看到自己經營的App有大幅度進步,實在令人振奮!

上次寫了 Firebase Performance 如何使用,也經過了一個多月,可以來見證我優化某功能的成果囉~🥳

廣告
(繼續閱讀…)

Instagram API 審核

每個一段時間,串接的第三方套件就整個大改,特別是非常大的服務如Facebook、Instagram、Google等平台,會提醒你在半年或一年不等的時間內盡快更新,舊有的SDK或API即將棄用不支援,這時候你不得不接受這突如其來的「指令」,畢竟我們所需要的服務都被他們一手掌握,賭氣不用的話很快死翹翹XD~

(繼續閱讀…)

[iOS] 棄用API的使用情況 (Deprecated API Usage)

2020年3月開始,上傳ipa檔到App Store,立刻收到上傳成功信,不過有點不太一樣的是,信中提醒有個問題未來必須解決⋯⋯目前可以暫時略過,直到2020年12月後若還沒解決,上傳ipa檔到App Store就會被拒絕!

哇~真是驚為天人,原本已經完美無瑕的功能,現在要被迫更新使用新的API。其實軟體就是如此,會隨著時間演化出更好的效能,與時俱進是較佳的做法,就像公司的產品,若一直是舊有的狀態,極有可能會被時代給遺棄。例如:Feature phone已被Smart phone取代啦~

原本在想只要搜尋本專案中有無關鍵字「UIWebView」,然而查到的解法,是連同所使用的第三方套件都必須一併移除,這可是大工程呢!於是要研究怎麼轉移到「WKWebView」。

(繼續閱讀…)

糟糕的API製作

一年前也就是2017/1/27的紀錄,我經手一個幼稚園案子,我以為只要負責開發App的部分即可,所以報價非常的親民,因為對方是我非常好的老闆朋友。不過最後證實,這個案子讓我公司虧錢,時間成本多出3倍,為了斬斷所有牽絆,在卡卡頓頓開發一年後,宣布不再接手維護。

以下就描述我身為軟體架構師觀察到的問題:

API開發

此案不明原因分成三個人⋯⋯

  • A創造規格人(實作原型)
  • B建立架構人(實作雛形)
  • C開發實作人(實作成品)

幼稚園案子.gif

照理說,ABC要同一人才是!因為每個人的邏輯思考不同,若分為三個人接續製作,最後成果極度可能四不像,那可是會大大增加開發成本!

(繼續閱讀…)

[iOS] 呼叫Web Service除錯

今天來講一下簡單的問題,不知道要怎麼稱呼這一篇,就姑且叫呼叫Web Service除錯吧~

其實就是串API時所發現的奇異問題!使用PostmanChrome呼叫都很成功回傳我要的資料,卻在寫進iOS中卻得到不預期的結果,先前有提到過Basic Authentication,程式傳遞token後,回傳結果表示沒有傳遞token給server,明明就是照先前的code複製貼上修改API Function名稱,這次居然有問題讓我很納悶。

人不是萬能,總得要投降來找救兵,以便跳出框框,看見問題的癥結。還是找我們寫後台的資深工程師幫忙查看,搞了兩小時多,Function名稱換掉也一樣,最後資深工程師發現,原來URL不小心多打一個「/」~

錯:
http://happystudio.notebook.com:5000/api/ecg/?start_date=2017-10-18&end_date=2017-11-17

對:
http://happystudio.notebook.com:5000/api/ecg?start_date=2017-10-18&end_date=2017-11-17

原因:?前多一個/

那為何Postman或Chrome測試沒有問題?因為這兩個工具會自動把沒有「/」,變成有「/」,來符合後台的API格式,然而iOS SDK就沒做這個容錯處理。這要歸類成相容性問題嗎?其實複製URL貼上到Chrome測試,我就有發現網址會跳成有「/」。

花了點時間,算是幫後台debug啦~

[iOS] 包含字串 (Contains String)

程式語言會隨著時間進化。本次專案依然會處理字串,我自己定義字串來區別用途,想知道是否包含字串 (Contains String),iOS 7以前的作法很拐彎抹角,我是查詢StackOverflow才知道,而且不是查詢一次就記起來,可見這支NSString的method有多不直覺!

iOS 8以後,就可以用「包含」這個方法:

containsString

我很自然地就使用它,在iPhone 6/6+跑都沒問題,因為一買來就是iOS 8。直到夥伴大鳥跟我說,用它iPhone 5一跑就崩潰,後來得知它手機還是iOS 7,就在想是那支method有問題。答案揭曉⋯⋯

/**
 Theme: Contains String
 IDE: Xcode 6
 Language: Objective C
 Date: 104/03/31
 Author: HappyMan
 Blog: https://cg2010studio.wordpress.com/
 */
/* containsString: returns YES if the target string is contained within the receiver. Same as calling rangeOfString:options: with no options, thus doing a case-sensitive, non-literal search. localizedCaseInsensitiveContainsString: is the case-insensitive variant. Note that it takes the current locale into effect as well.  Locale-independent case-insensitive operation, and other needs can be achieved by calling rangeOfString:options:range:locale: directly.
 */
- (BOOL)containsString:(NSString *)aString NS_AVAILABLE(10_10, 8_0);

//--

/* These methods return length==0 if the target string is not found. So, to check for containment: ([str rangeOfString:@"target"].length > 0).  Note that the length of the range returned by these methods might be different than the length of the target string, due composed characters and such.
*/
- (NSRange)rangeOfString:(NSString *)aString;

//--

    NSString *str;
    if ([str rangeOfString:@"HappyDay"].location != NSNotFound) {
        // iOS 7以前拐彎抹角
    }

    if ([str containsString:@"HappyDay"]) {
        // iOS 8以後可以很開心
    }

把method的名稱設計得很直覺,真的是件好事呀~

參考:。

標籤雲