All Projects → appcelerator-modules → Ti.urlsession

appcelerator-modules / Ti.urlsession

Licence: other
Use the NSURLSession API to download and upload files in Titanium.

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Ti.urlsession

Azteceditor Android
A reusable native Android rich text editor component.
Stars: ✭ 518 (+7300%)
Mutual labels:  native
Sauron Native
Truly cross platform, truly native. multiple backend GUI for rust
Stars: ✭ 587 (+8285.71%)
Mutual labels:  native
Delphimvcframework
DMVCFramework (for short) is a popular and powerful framework for web solution in Delphi. Supports RESTful and JSON-RPC APIs development.
Stars: ✭ 761 (+10771.43%)
Mutual labels:  native
Silk.net
The high-speed OpenAL, OpenGL, Vulkan, and GLFW bindings library your mother warned you about.
Stars: ✭ 534 (+7528.57%)
Mutual labels:  native
Klock
Multiplatform Date and time library for Kotlin
Stars: ✭ 569 (+8028.57%)
Mutual labels:  native
Proton
Purely native and extensible rich text editor for iOS and macOS Catalyst apps
Stars: ✭ 685 (+9685.71%)
Mutual labels:  native
Nativescript Vue
Native mobile applications using Vue and NativeScript.
Stars: ✭ 4,784 (+68242.86%)
Mutual labels:  native
Xtd forms
Modern c++17 library to create native gui for Microsoft Windows, Apple macOS and Linux.
Stars: ✭ 25 (+257.14%)
Mutual labels:  native
Vue Nodegui
Build performant, native and cross-platform desktop applications with native Vue + powerful CSS like styling.🚀
Stars: ✭ 575 (+8114.29%)
Mutual labels:  native
Nativeshare
NativeShare是一个整合了各大移动端浏览器调用原生分享的插件
Stars: ✭ 751 (+10628.57%)
Mutual labels:  native
Camerakit Android
Library for Android Camera 1 and 2 APIs. Massively increase stability and reliability of photo and video capture on all Android devices.
Stars: ✭ 5,131 (+73200%)
Mutual labels:  native
Clickhouse Driver
ClickHouse Python Driver with native interface support
Stars: ✭ 562 (+7928.57%)
Mutual labels:  native
Sticky State
StickyState is a high performant module making native position:sticky statefull and polyfilling the missing sticky browser feature
Stars: ✭ 692 (+9785.71%)
Mutual labels:  native
Dearpygui
Dear PyGui: A fast and powerful Graphical User Interface Toolkit for Python with minimal dependencies
Stars: ✭ 6,631 (+94628.57%)
Mutual labels:  native
Slim.js
Fast & Robust Front-End Micro-framework based on modern standards
Stars: ✭ 789 (+11171.43%)
Mutual labels:  native
Brisk
✨Cross-platform set of tools for building native UIs with Reason/OCaml
Stars: ✭ 518 (+7300%)
Mutual labels:  native
React Nodegui
Build performant, native and cross-platform desktop applications with native React + powerful CSS like styling.🚀
Stars: ✭ 5,914 (+84385.71%)
Mutual labels:  native
React Native Geolocation Service
React native geolocation service for iOS and android
Stars: ✭ 934 (+13242.86%)
Mutual labels:  native
Savannakit
A high-performance, protocol oriented, framework for creating native IDEs for iOS and macOS, written in Swift
Stars: ✭ 816 (+11557.14%)
Mutual labels:  native
React Native Canvas
A Canvas component for React Native
Stars: ✭ 736 (+10414.29%)
Mutual labels:  native

Ti.URLSession Module

Description

Creates a lightweight wrapper around NSURLSession for working with the Backgrounding Features.

Accessing the urlSession Module

To access this module from JavaScript, you would do the following:

var URLSession = require('com.appcelerator.urlSession');

The URLSession variable is a reference to the Module object.

Module

Methods

createSessionConfiguration(arguments)

Creates a preconfigured session configuration object that can be used to create a URLSession for performing a background the download task.

  • Takes one argument, a string: An object with the identifier of the new session configuration that is unique for your app. Your app can retrieve the download or the upload response later by creating a new background session with the same identifier. Also, you can set the HTTPHeaderFields property to specify additional HTTP header-fields.

Returns a preconfigured session configuration object. This variable needs to be passed into the createURLSession() function to create a session for background download.

createURLSession(sessionConfig)

Creates a session with the specified session configuration. If the session configuration was created with the identifier of a existing session, then this function would return the pre-existing session.

  • Takes one argument, a session configuration object: Created using createSessionConfiguration().

Returns a session object.

ImportantThe session object keeps a strong reference until your app explicitly invalidates the session. If you do not invalidate the session by calling the invalidateAndCancel() or finishTasksAndInvalidate() method, your app leaks memory.

SessionConfiguration

Properties

  • identifier (String, creation-only)
  • HTTPHeaderFields (Array<String: String>)

Session

Methods

downloadTask(arguments)

Creates a download task for the specified URL, within the provided session object and saves the results to a file. Once this function is called, the download starts automatically. The progress of the download can be monitored by listening to downloadprogress , downloadcompleted, sessioneventscompleted and sessioncompleted events explained below.

  • Takes an object of one argument:
    • url (String): The remote url used for this data task.

uploadTask(arguments)

Creates an upload task for the specified URL, within the provided session object and the file-blob to upload. Once this function is called, the upload starts automatically. The progress of the upload can be monitored by listening to uploadprogress and sessioncompleted events explained below.

  • Takes an object of arguments:
    • url (String): The remote url used for this upload task.
    • data (TiBlob): The data blob used for this upload task.
    • method (String): The request method (e.g. POST or PUT). Default: POST.
    • requestHeaders (Array<String: String>): Additional request headers to pass to the request.

Returns the new created task's identifier number.

dataTask(arguments)

Creates a data task for the specified URL, within the provided session object and local data. An data task does not provide any additional functionality over a usual session task and its presence is merely to provide lexical differentiation from download and upload tasks.

Once this function is called, the task starts automatically. Once finished, the data task will call the sessioncompleted event containing infos about the response.

  • Takes an object of arguments:
    • url (String): The remote url used for this data task.
    • data (TiBlob): The data blob used for this data task.
    • method (String): The request method (e.g. POST or PUT). Default: POST.
    • requestHeaders (Array<String: String>): Additional request headers to pass to the request.

Returns the new created task's identifier number.

finishTasksAndInvalidate()

Invalidates the given session object, allowing any outstanding tasks to finish.

This method returns immediately without waiting for tasks to finish. Once a session is invalidated, new tasks cannot be created in the session, but existing tasks continue until completion. Once invalidated, references to the events and callback objects are broken. Session objects cannot be reused. To cancel all outstanding tasks, call invalidateAndCancel() instead.

  • Takes one argument, a session object : the session which the user wants to invalidate.

invalidateAndCancel()

Cancels all outstanding tasks and then invalidates the session object.

Once invalidated, references to the events and callback objects are broken. Session objects cannot be reused. To allow outstanding tasks to run until completion, call finishTasksAndInvalidate() instead.

reset(callback)

Empties all cookies, cache and credential stores, removes disk files and calls flush() internally. Calls the callback when the reset is finished.

flush(callback)

Flushes storage to disk and clear transient network caches. Calls the callback when the flush is finished.

Events

downloadprogress

Periodically informs the user about the download's progress.

ImportantThis event is exposed inside Ti.App.iOS Proxy. usage :

Ti.App.iOS.addEventListener('downloadprogress', function(e) {
  // Handle the download progress
});

The following event information will be provided:

  • taskIdentifier (Number) : The task identifier number for the download task that finished.
  • bytesWritten (Number) : The number of bytes transferred since the last time this delegate method was called.
  • totalBytesWritten (Number) : The total number of bytes transferred so far.
  • totalBytesExpectedToWrite (Number) : The expected length of the file, as provided by the Content-Length header. If this header was not provided, the value is zero.

downloadcompleted

Informs the app that a download task has finished downloading.

ImportantThis event is exposed inside Ti.App.iOS Proxy. usage :

Ti.App.iOS.addEventListener('downloadcompleted', function(e) {
  // Handle the completed download
});

The following event information will be provided:

taskIdentifier[int]: The task identifier number for the download task that finished. dataTiBlob : The downloaded content as blob object

sessioneventscompleted

If an application has received an backgroundtransfer event, this session event will be fired to indicate that all messages previously enqueued for this session have been delivered. At this time it is safe to invoke the previously stored completion handler

ImportantThis event is exposed inside Ti.App.iOS Proxy. usage :

Ti.App.iOS.addEventListener('sessioneventscompleted', function(e) {
  // Handle completed session events
});

sessioncompleted

Informs the app that the task finished transfering data.

ImportantThis event is exposed inside Ti.App.iOS Proxy. usage :

Ti.App.iOS.addEventListener('sessioncompleted', function(e) {
  // Handle a finished transfer
});

The following event information will be provided:

  • taskIdentifier (Number) : The task identifier number for the download or upload task that finished.
  • success (Boolean) : Indicates if the operation succeeded. Returns true if download or upload succeeded, false otherwise.
  • errorCode (Number) : The error code of the error, if any (potentially system-dependent).
  • message (String) : A string containing the localized description of the error.

Usage

See the full features example.

Author

Hans Knoechel / Sabil Rahim

Feedback and Support

Please direct all questions, feedback, and concerns to [email protected] or ask the community on TiSlack.

License

Copyright (c) 2010-Present by Axway Appcelerator. All Rights Reserved. Please see the LICENSE file included in the distribution for further details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].