Name: API
Owner: Droids On Roids
Description: null
Created: 2016-03-11 22:18:44.0
Updated: 2016-03-15 08:24:23.0
Pushed: 2016-03-15 15:25:18.0
Homepage: null
Size: 124
Language: Swift
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
W tym repozytorium znajdziemy klas? SnapchatAPI
, która jest gotowa do wysy?ania obrazka na serwer.
Jest tam zaimplementowana tylko jedna metoda, której zadaniem jest wys?anie obrazka do wszystkich u?ytkowników:
ic func upload(image image: UIImage, completion: () -> ()) {
.
Na podstawie implementacji tej funkcji zaimplementowane s? funkcje upload(image:toUser:completion:)
, getImages(parameters:completion:)
, getImages(forUser:completion)
oraz downloadImage(url:completion)
.
Funkcja upload
mo?e zosta? wywo?ana tak jak w UploadViewController
:
chatAPI.upload(image: __UIIMAGE__) { [unowned self] in
The request has finished and this is completion block.
You can do something like stop spinner or enable buttons etc.
Funkcja ta sama w sobie robi 2 rzeczy. Pierwsza to zamiana UIImage
na NSData
, która jest potrzebna, aby wys?a? obrazek na serwer. Druga to ju? request, czyli wys?anie zapytania POST na serwer. W wywo?aniu metody Alamofire
mamy 3 parametry (oczywi?cie w naszym przypadku): pierwszy to metoda wys?ania (.POST, .GET etc.), drugi to URL (bierzemy to z SnapchatAPIConstants
), trzeci parameter to w?a?nie data
, czyli nasz przetransformowany obrazek. Je?li chcemy by? powiadomieni o zako?czeniu operacji lub o np. odpowiedzi od serwera, mamy wtedy funkcje response
, która zwraca nam dane w postaci czystej NSData
, ale mamy równie? funkcje responseJSON
, która nam od razu parsuje odpowied? jako JSON. Tutaj tak?e mamy tzw. completionHandler
czy completionBlock
, który zawiera informacje o zako?czonym requescie.