The Newsstand module allows you to access Apple's NewsKit APIs
This module requires iOS 5 or greater
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.
View the Using Titanium Modules document for instructions on getting started with using this module in your application.
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.
UINewsstandBindingEdge
and UINewsstandBindingType
values to get different decorations on the icons. Available options can be found in Apple's CoreFoundationKeys Documentation.newsstandicon.png
to the 'Resources/iphone' directory next to appicon.pngtiapp.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 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();
}
}
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.
The issue has assets that are currently downloading.
The issue has assets that are currently downloading.
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.
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
.
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. 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.
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;
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.
Adds the specified callback as an event listener for the named event.
Name of the event.
Callback function to invoke when the event is fired.
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
});
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();
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();
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();
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"
});
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);
Name of the event.
Callback function to remove. Must be the same function passed to addEventListener
.
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);
The issue to be removed.
Sets the value of the applicationIconBadgeNumber property.
New value for the property.
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"
});
Sets the value of the currentlyReadingIssue property.
New value for the property.
Sets the value of the iconImage property.
New value for the property.
Sets the value of the lifecycleContainer property.
New value for the property.
Occurs when each asset download completes.
The unique name of the issue the asset is being downloaded for.
The dictionary of key value pairs that was set when calling Modules.Newsstand.Issue.downloadAsset.
The location of the file that was downloaded.
Source object that fired the event.
Name of the event fired.
True if the event will try to bubble up if possible.
Set to true to stop the event from bubbling.
Occurs when there is an error while downloading an asset.
The unique name of the issue the asset is being downloaded for.
The dictionary of key value pairs that was set when calling Modules.Newsstand.Issue.downloadAsset.
Description of the error.
The error code.
Source object that fired the event.
Name of the event fired.
True if the event will try to bubble up if possible.
Set to true to stop the event from bubbling.
Occurs when all of the asset downloads that have been started for an issue are complete. This could be a successful completion or error.
The unique name of the issue.
Source object that fired the event.
Name of the event fired.
True if the event will try to bubble up if possible.
Set to true to stop the event from bubbling.
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.
The unique name of the issue the asset is being downloaded for.
The dictionary of key value pairs that was set when calling Modules.Newsstand.Issue.downloadAsset.
The number of bytes downloaded.
The total number of bytes to download for the current asset.
Source object that fired the event.
Name of the event fired.
True if the event will try to bubble up if possible.
Set to true to stop the event from bubbling.