ios - Google Drive API (GTL) - Create multiple folder paths in order? -
i'm using google apis client library objective-c (gtl) access google drive api.
according it's introduction google apis client library objective-c,
query execution service inherently asynchronous.
which means when try create path like: root/a/b/c
, before can create folder b
, you'll have to:
make sure
a
created, if not, create beforeb
trying check it'sparentref
.know
id
of foldera
can createb
in it.
and same goes c
.
i use following id
of folder name within known parent folder id:
// parentid name "parent". let query = gtlquerydrive.queryforchildrenlistwithfolderid(parentid) query.q = "mimetype='application/vnd.google-apps.folder' , '\(parentid)' in parents , trashed=false , title='\(name)'" query.maxresults = 1 gtlfileticket = gtldriveservice.executequery( query, completionhandler: {( ticket: gtlserviceticket!, object: anyobject!, error: nserror!) -> void in // callback self.gtlfileticket = nil if error == nil { // id object. if nil make query create folder named "name" within folder "parentid". } else { // error handles here. } })
in other part of project, called above method within loop:
var parent = "root" item in array { createfolderifnotexisted(item, parent: parent) parent = item }
apparently, fail , end creating first folder 2nd query starts before 1st query finished. googled around didn't see way make synchronous calls instead. (tho saw java api branch can have .await()
?)
is there way make sure calls can executed in sequence?
avoid using synchronous loop. createfolder function should call when it's complete; callback should start next loop iteration.
Comments
Post a Comment