Modules.Newsstand
> Modules.Newsstand

The Newsstand module allows you to access Apple's NewsKit APIs

Requirements

This module requires iOS 5 or greater

Newsstand Resources

Publishing

Apple allows you to update your app icon in iTunes connect so that the latest issue can always be displayed. Documentation around setting this up can be found in the iTunes Connect Developer Guide.

Getting Started

View the Using Titanium Modules document for instructions on getting started with using this module in your application.

Accessing the Newsstand Module

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

var Newsstand = require("ti.newsstand");

The newsstand variable is a reference to the Module object.

Setup

  1. Setup the app as a Newsstand app by adding the code below to your tiapp.xml
  2. Modify the UINewsstandBindingEdge and UINewsstandBindingType values to get different decorations on the icons. Available options can be found in Apple's CoreFoundationKeys Documentation.
  3. Add newsstandicon.png to the 'Resources/iphone' directory next to appicon.png
  4. Run the app, you should see it in the Newsstand folder.
  5. During development, be sure to call enableDevMode to remove the daily download limit.

tiapp.xml

<ios>
    <plist>
        <dict>
            <key>CFBundleIcons</key>
            <dict>
                <key>CFBundlePrimaryIcon</key>
                <dict>
                    <key>CFBundleIconFiles</key>
                    <array>
                        <string>appicon.png</string>
                    </array>
                </dict>
                <key>UINewsstandIcon</key>
                <dict>
                    <key>CFBundleIconFiles</key>
                    <array>
                        <string>newsstandicon.png</string>
                    </array>
                    <key>UINewsstandBindingEdge</key>
                    <string>UINewsstandBindingEdgeLeft</string>
                    <key>UINewsstandBindingType</key>
                    <string>UINewsstandBindingTypeMagazine</string>
                </dict>
            </dict>
            <key>UINewsstandApp</key>
            <true/>
            <key>UIBackgroundModes</key>
            <array>
                <string>newsstand-content</string>
            </array>
        </dict>
    </plist>
</ios>

Push Notifications

Push notifications can be sent to the device to notify it that a new issue is available. The notification payload must contain a "content-available" key set to 1. If this is not set, iOS will not allow the application to wake in the background to download a new issue.

{
  "aps":{
    "content-available":1,
        },
   "device_tokens": ["exampleToken4F2509D125889AED3466F4D1376B26C374190B3974739"]
}

Use the Titanium.Network.NOTIFICATION_TYPE_NEWSSTAND type when calling Titanium.Network.registerForPushNotifications

Ti.Network.registerForPushNotifications({
    types:[
        Ti.Network.NOTIFICATION_TYPE_NEWSSTAND
    ],
    success: eventSuccess,
    error: eventError,
    callback: eventCallback
});

To enable your application to download assets in the background in response to a push notification, you must wrap your Modules.Newsstand.Issue.downloadAsset calls with calls to beginBackgroundDownloadRequests and endBackgroundDownloadRequests.

For example, the event callback specified for Titanium.Network.registerForPushNotifications might look like the following:

function eventCallback(e) {
    if (e.data['content-available'] === 1) {
        Newsstand.beginBackgroundDownloadRequests();
        var issue = Newsstand.getIssue({
            name: issues[0].name
        }); 
        if (!issue) {
            // if issue is not found then add it
            issue = Newsstand.addIssue({
                name: name,
                date: new Date()
            });
        }
        issue.downloadAsset({
            url: issues[0].content,
            userInfo: {
                id: 9999,
                name: 'TESTBACKGROUND'
            }
        });
        Newsstand.endBackgroundDownloadRequests();
    }
}
  • 1.0.0
  • 1.0.0
Defined By

Properties

Modules.Newsstand
ISSUE_CONTENT_STATUS_AVAILABLE : Numberreadonly

Downloading of assets is not taking place and there is issue content at contentURL.

Downloading of assets is not taking place and there is issue content at contentURL.

Modules.Newsstand
ISSUE_CONTENT_STATUS_DOWNLOADING : Numberreadonly

The issue has assets that are currently downloading.

The issue has assets that are currently downloading.

Modules.Newsstand
ISSUE_CONTENT_STATUS_NONE : Numberreadonly

Assets are not downloading for the issue and there is no content at contentURL.

Assets are not downloading for the issue and there is no content at contentURL.

apiName : Stringreadonly

The name of the API that this proxy corresponds to.

The name of the API that this proxy corresponds to.

The value of this property is the fully qualified name of the API. For example, Button returns Ti.UI.Button.

  • 3.2.0
  • 3.2.0
  • 3.2.0
Modules.Newsstand
: Number
Accesses or sets the icon badge number of the app. ...

Accesses or sets the icon badge number of the app. Instead of displaying a badge number on the app icon, this will set the "new" badge on the app icon if the number is greater than 0.

Accesses or sets the newsstand issue that the user is currently reading. ...

Accesses or sets the newsstand issue that the user is currently reading. If no issue is set, it will be undefined.

Newsstand Kit takes this setting into consideration when it purges back issues because of low levels of available flash storage.

Modules.Newsstand
iconImage : Titanium.Filesystem.Filewriteonly

Sets the image of the application icon.

Sets the image of the application icon.

Note: If the image is not within the dimensions outlined in the Newsstand Icon section of the iOS Human Interface Guidelines, it may not be displayed.

Note: Sometimes this does not work on the simulator. Works consistently on device.

Example

var file = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'newIcon.png');
Newsstand.iconImage = file;
Modules.Newsstand
issues : Modules.Newsstand.Issue[]readonly

Returns an array of Modules.Newsstand.Issues representing the current issues in the library.

Returns an array of Modules.Newsstand.Issues representing the current issues in the library.

The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.

The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.

If this property is set to a Window or TabGroup, then the corresponding Activity lifecycle event callbacks will also be called on the proxy. Proxies that require the activity lifecycle will need this property set to the appropriate containing Window or TabGroup.

  • 3.6.0
Defined By

Methods

Adds the specified callback as an event listener for the named event. ...

Adds the specified callback as an event listener for the named event.

Parameters

  • name : String

    Name of the event.

  • callback : Callback<Object>

    Callback function to invoke when the event is fired.

Returns

  • void
Modules.Newsstand
( props ) : Modules.Newsstand.Issue
Adds an issues to the library. ...

Adds an issues to the library.

Throws an exception if name and date are invalid. Also throws an exception if you use a name that is already taken by another issue.

Returns a Modules.Newsstand.Issue representing the issue that was added to the library or undefined if the issues could not be added to the library.

Example

var issueDate = new Date();
issueDate.setFullYear(2013);
issueDate.setMonth(0);
issueDate.setDate(14);
var issue = Newsstand.addIssue({
    name: "Magazine-0", 
    date: issueDate
});

Parameters

Returns

Signals the start of a series of Modules.Newsstand.Issue.downloadAsset calls. ...

Signals the start of a series of Modules.Newsstand.Issue.downloadAsset calls. This call notifies the device that additional time may be needed by the application while running in the background.

Example

Newsstand.beginBackgroundDownloadRequests();
issue1.downloadAsset(...);
issue2.downloadAsset(...);
Newsstand.endBackgroundDownloadRequests();

Returns

  • void
Modules.Newsstand
( )
Newsstand push notifications are only allowed one background download per day. ...

Newsstand push notifications are only allowed one background download per day. This function will disable this limit for development devices during testing.

Note: A development device refers to a device which has been recognized in Xcode Organizer as having the "Use for Development" checkbox enabled.

Example

Newsstand.enableDevMode();

Returns

  • void
Modules.Newsstand
( )
Signals the end of a series of Modules.Newsstand.Issue.downloadAsset calls. ...

Signals the end of a series of Modules.Newsstand.Issue.downloadAsset calls. This call notifies the device that the application no longer requires additional time while running in the background.

Example

Newsstand.beginBackgroundDownloadRequests();
issue1.downloadAsset(...);
issue2.downloadAsset(...);
Newsstand.endBackgroundDownloadRequests();

Returns

  • void
Gets the value of the apiName property. ...

Gets the value of the apiName property.

  • 3.2.0
  • 3.2.0
  • 3.2.0

Returns

  • String
Modules.Newsstand
( ) : Number
Gets the value of the applicationIconBadgeNumber property. ...

Gets the value of the applicationIconBadgeNumber property.

Returns

  • Number
Gets the value of the currentlyReadingIssue property. ...

Gets the value of the currentlyReadingIssue property.

Returns

Modules.Newsstand
( props ) : Modules.Newsstand.Issue
Retrieves an issue from the library via its unique name. ...

Retrieves an issue from the library via its unique name.

Returns a Modules.Newsstand.Issue representing the issue or undefined if the issue does not exist in the library.

Example

var issue = Newsstand.getIssue({
    name: "Magazine-0"
});

Parameters

Returns

Modules.Newsstand
( ) : Modules.Newsstand.Issue[]
Gets the value of the issues property. ...

Gets the value of the issues property.

Returns

Gets the value of the lifecycleContainer property. ...

Gets the value of the lifecycleContainer property.

  • 3.6.0

Returns

Removes the specified callback as an event listener for the named event. ...

Removes the specified callback as an event listener for the named event.

Multiple listeners can be registered for the same event, so the callback parameter is used to determine which listener to remove.

When adding a listener, you must save a reference to the callback function in order to remove the listener later:

var listener = function() { Ti.API.info("Event listener called."); }
window.addEventListener('click', listener);

To remove the listener, pass in a reference to the callback function:

window.removeEventListener('click', listener);

Parameters

  • name : String

    Name of the event.

  • callback : Callback<Object>

    Callback function to remove. Must be the same function passed to addEventListener.

Returns

  • void
Modules.Newsstand
( issue )
Removes an issue from the library. ...

Removes an issue from the library.

Note: It is possible to hold on to a Modules.Newsstand.Issue even after it is removed from the library. This is not something you want to do, because issues are useless if they are not in the library. Most of the properties of the issue will still be available excelpt contentURL which will be undefined.

Example

Newsstand.removeIssue(issueToRemove);

Parameters

Returns

  • void
Modules.Newsstand
( applicationIconBadgeNumber )
Sets the value of the applicationIconBadgeNumber property. ...

Sets the value of the applicationIconBadgeNumber property.

Parameters

  • applicationIconBadgeNumber : Number

    New value for the property.

Returns

  • void
Modules.Newsstand
( props )
Sets the username and password that will be used if the Modules.Newsstand.Issue.downloadAsset call needs to authentic...

Sets the username and password that will be used if the Modules.Newsstand.Issue.downloadAsset call needs to authenticate.

Example

Newsstand.setBasicAuthentication({
    username: "jalter",
    password: "password"
});

Parameters

Returns

  • void
Modules.Newsstand
( currentlyReadingIssue )
Sets the value of the currentlyReadingIssue property. ...

Sets the value of the currentlyReadingIssue property.

Parameters

Returns

  • void
Modules.Newsstand
( iconImage )
Sets the value of the iconImage property. ...

Sets the value of the iconImage property.

Parameters

Returns

  • void
Sets the value of the lifecycleContainer property. ...

Sets the value of the lifecycleContainer property.

  • 3.6.0

Parameters

Returns

  • void
Defined By

Events

Modules.Newsstand
Occurs when each asset download completes. ...

Occurs when each asset download completes.

Properties

  • name : String

    The unique name of the issue the asset is being downloaded for.

  • userInfo : Object

    The dictionary of key value pairs that was set when calling Modules.Newsstand.Issue.downloadAsset.

  • filePath : String

    The location of the file that was downloaded.

  • source : Object

    Source object that fired the event.

    •  
    •  
    •  
  • type : String

    Name of the event fired.

    •  
    •  
    •  
  • bubbles : Boolean

    True if the event will try to bubble up if possible.

    •  
    •  
    •  
  • cancelBubble : Boolean

    Set to true to stop the event from bubbling.

    •  
    •  
    •  
Modules.Newsstand
Occurs when there is an error while downloading an asset. ...

Occurs when there is an error while downloading an asset.

Properties

  • name : String

    The unique name of the issue the asset is being downloaded for.

  • userInfo : Object

    The dictionary of key value pairs that was set when calling Modules.Newsstand.Issue.downloadAsset.

  • description : String

    Description of the error.

  • code : String

    The error code.

  • source : Object

    Source object that fired the event.

    •  
    •  
    •  
  • type : String

    Name of the event fired.

    •  
    •  
    •  
  • bubbles : Boolean

    True if the event will try to bubble up if possible.

    •  
    •  
    •  
  • cancelBubble : Boolean

    Set to true to stop the event from bubbling.

    •  
    •  
    •  
Modules.Newsstand
Occurs when all of the asset downloads that have been started for an issue are complete. ...

Occurs when all of the asset downloads that have been started for an issue are complete. This could be a successful completion or error.

Properties

  • name : String

    The unique name of the issue.

  • source : Object

    Source object that fired the event.

    •  
    •  
    •  
  • type : String

    Name of the event fired.

    •  
    •  
    •  
  • bubbles : Boolean

    True if the event will try to bubble up if possible.

    •  
    •  
    •  
  • cancelBubble : Boolean

    Set to true to stop the event from bubbling.

    •  
    •  
    •  
Modules.Newsstand
Occurs if you call downloadAsset and an issue asset is downloading. ...

Occurs if you call downloadAsset and an issue asset is downloading. This event is only sent when the application is running in the foreground.

Note: totalBytes only applies to the current file being downloaded.

Properties

  • name : String

    The unique name of the issue the asset is being downloaded for.

  • userInfo : Object

    The dictionary of key value pairs that was set when calling Modules.Newsstand.Issue.downloadAsset.

  • bytesWritten : Number

    The number of bytes downloaded.

  • totalBytes : Number

    The total number of bytes to download for the current asset.

  • source : Object

    Source object that fired the event.

    •  
    •  
    •  
  • type : String

    Name of the event fired.

    •  
    •  
    •  
  • bubbles : Boolean

    True if the event will try to bubble up if possible.

    •  
    •  
    •  
  • cancelBubble : Boolean

    Set to true to stop the event from bubbling.

    •  
    •  
    •