Building newsstand_apps

Preview:

DESCRIPTION

How to develop nice magazines to newsstand of Apple...

Citation preview

These are confidential sessions—please refrain from streaming, blogging, or taking pictures

Session 504

Building Newsstand Apps

Ben NielseniOS Application Engineering

1

2

3

4

5

2222222

6

NewsstandThe look

7

The lookNewsstand

• Repository for publications

• Richer visual experience

• Icons reflect content

• iTunes Store integration

8

NewsstandKit

• Push notification updates

• Content organization

• Background downloads

NewsstandKitNKLibraryNKIssue

NKAssetDownload

Your App

Foundation

UIKit

9

What You’ll Learn

• Appearing in Newsstand

• Retrieving content

• Presenting content

10

Appearing in Newsstand

Jon DrummondiOS Application Engineering

11

Appearing in NewsstandBecoming a Newsstand app

• Add one key to your Info.plist<key>UINewsstandApp</key>

<true/>

• You’re now a Newsstand app!• But you need an icon…

12

Time for an icon

• One icon style in iOS 4■ Home screen■ Search■ Settings■ App switcher■ Notifications

Appearing in Newsstand

13

14

Appearing in Newsstand

• Distinct from standard app icons■ Home screen and app switcher

• Should reflect your content• Dynamic—can be updated after your app is installed

• Additional adornment for magazine and newspaper styles

Newsstand icons

15

Appearing in NewsstandStandard icons

• We still need them!■ Settings, Search, Notifications…

• Newsstand icon must be defined in addition to the standard icon

16

Appearing in NewsstandStandard icon specification

• Top-level key in your Info.plist with an array of image names

<key>CFBundleIconFiles</key>

<array>

! <string>Icon.png</string>

! <string>Icon@2x.png</string>

...

</array>

17

Newsstand icons

• A new top-level Info.plist key■ CFBundleIcons—a dictionary of icon styles

UINewsstandIcon

Appearing in Newsstand

CFBundlePrimaryIcon

18

Appearing in NewsstandUpdating your Info.plist

<key>CFBundleIconFiles</key>

<array>

<string>Icon.png</string>

<string>Icon@2x.png</string>

</array>

<key>CFBundleIcons</key>

<dict>New top-level key

Existing CFBundleIconFiles

Icon style key<key>CFBundlePrimaryIcon</key>

<dict>

</dict>

</dict>

19

Appearing in NewsstandUpdating your Info.plist

<key>CFBundleIconFiles</key>

<array>

<string>Icon.png</string>

<string>Icon@2x.png</string>

</array>

<key>CFBundleIcons</key>

<dict>New top-level key

Existing CFBundleIconFiles

Icon style key<key>CFBundlePrimaryIcon</key>

<dict>

</dict>

</dict>

<key>CFBundlePrimaryIcon</key>

<dict>...</dict>

20

Appearing in NewsstandCustomizing your Newsstand icon

• Icons are adorned to resemble their physical counterparts■ Newspaper or magazine?■ Binding edge

• Exist as keys inside the UINewsstandIcon style dictionary

21

Customizing your Newsstand iconAppearing in Newsstand

UINewsstandBindingEdgeLeftUINewsstandBindingEdgeRightUINewsstandBindingEdgeBottom

Fold

Stack

UINewsstandBindingTypeNewspaperUINewsstandBindingTypeMagazine

Staples Pages

22

Appearing in NewsstandUpdating your Info.plist

<key>CFBundleIcons</key><dict>

<key>UINewsstandIcon</key><dict>

<key>CFBundleIconFiles</key>...</array>

</dict>

</dict>

Options

Newsstand style key and icon files

<key>UINewsstandBindingType</key>

<string>UINewsstandBindingTypeNewspaper</string><key>UINewsstandBindingEdge</key>

<string>UINewsstandBindingEdgeBottom</string>

23

Appearing in NewsstandAdditional considerations

• Icons need not be square■ Use a shape that matches your physical appearance

• You must still include CFBundlePrimaryIcon■ Standard and Newsstand icon are both needed

• Backward compatibility■ CFBundleIcons is required for Newsstand apps in iOS 5■ Can coexist with existing icon keys for earlier versions of iOS

24

Creating a Newsstand AppDemo

25

Handling Updates

Ben NielseniOS Application Engineering

26

Retrieving and presenting content

• Informing the app• Organizing issues• Downloading content• Updating your icon

Handling Updates

ORGANIZINGUPDATING

INFORMING

DOWNLOADING

27

Informing the AppHandling Updates

28

Informing the AppPush notifications

DOWNLOADING

ORGANIZINGUPDATING

INFORMING

29

‘content-available’:1

Informing the AppNewsstand Push Notifications

• Registration TypeUIRemoteNotificationTypeNewsstandContentAvailability

• Payload Key{

‘aps’:{

}

}

• Once per day■ NSUserDefaults: @”NKDontThrottleNewsstandContentNotifications”

DOWNLOADING

ORGANIZINGUPDATING

INFORMING

30

<key>UIBackgroundModes</key>

<array>

<string> </string>

</array>

newsstand-content

Informing the AppNewsstand Push Notifications

• Background mode

• Limited time-[UIApplication beginTaskWithExpirationHandler:]

DOWNLOADING

ORGANIZINGUPDATING

INFORMING

31

Organizing issuesHandling Updates

32

Organizing IssuesUsing NKLibrary

• Provides persistent state for:■ Available issues■ Ongoing downloads■ Issue being read

• Organizes issues■ Uses app’s Caches directory■ Improves resource management

DOWNLOADING

UPDATING

INFORMING

ORGANIZING

33

Organizing IssuesNKIssues

• Creating issues■ Unique name■ Publication date

NKIssue *myIssue = [myLibrary addIssueWithName:issueName date:issueDate];

■ Maintains a repository within the libraryNSURL *baseURL = [myIssue contentURL];

• Setting the current issue[myLibrary setCurrentlyReadingIssue:myIssue];

DOWNLOADING

UPDATING

INFORMING

ORGANIZING

34

Downloading contentHandling Updates

35

Downloading ContentNKAssetDownload

• Handles data transfer■ Keeps going

• Uses NSURLConnectionDelegate• Wake for critical events

newsstand-content

• Wi-Fi only in background

UPDATING

INFORMING

ORGANIZING

DOWNLOADING

36

for (item in itemsToDownload) {

}

Setup

NSURLRequest *downloadRequest = [item URLRequest];

NKAssetDownload *asset = [issue addAssetWithRequest:downloadRequest];

NSArray *itemsToDownload = !! query server for list of assets

for (item in itemsToDownload) {

}

Downloading Content

NSArray *itemsToDownload = !! query server for list of assets

NSURLRequest *downloadRequest = [item URLRequest];

NKAssetDownload *asset = [issue addAssetWithRequest:downloadRequest];

NSURLConnection *connection = [asset downloadWithDelegate:myDelegate];

UPDATING

INFORMING

ORGANIZING

DOWNLOADING

37

NSURLConnectionDownloadDelegate

[asset downloadWithDelegate:myDelegate];

• Implements NSURLConnectionDelegate■ Status■ Authentication■ Completion

• Modifications-connection:didReceiveData:

Downloading Content UPDATING

INFORMING

ORGANIZING

DOWNLOADING

NSURLConnectionDownloadDelegate

38

Downloading ContentNSURLConnectionDownloadDelegate

[asset downloadWithDelegate:myDelegate];

• Implements NSURLConnectionDelegate■ Status■ Authentication■ Completion

• Modifications-connection:didWriteData:totalBytesWritten:expectedTotalBytesWritten:

-connectionDidResumeDownloading:totalBytesWritten:expectedTotalBytesWritten:

-connectionDidFinishLoading:

UPDATING

INFORMING

ORGANIZING

DOWNLOADING

39

Downloading ContentNSURLConnectionDownloadDelegate

[asset downloadWithDelegate:myDelegate];

• Implements NSURLConnectionDelegate■ Status■ Authentication■ Completion

• Modifications-connection:didWriteData:totalBytesWritten:expectedTotalBytesWritten:

-connectionDidResumeDownloading:totalBytesWritten:expectedTotalBytesWritten:

-connectionDidFinishDownloading:destinationURL: required

UPDATING

INFORMING

ORGANIZING

DOWNLOADING

40

Downloading ContentBackground

• What if the app is suspended?■ No status updates■ Wakes for authentication and completion

• What if the app is terminated!?■ Relaunched in the background

UIApplicationLaunchOptionsNewsstandDownloadsKey

NSString *assetIdentifier = [myAssetDownload identifier];

UPDATING

INFORMING

ORGANIZING

DOWNLOADING

41

Reconnecting

• Reconnect on launchNKLibrary *library = [NKLibrary sharedLibrary];

for (NKAssetDownload *asset in [library downloadingAssets])

NSURLConnection *connection = [asset downloadWithDelegate:myDelegate];

• Always!■ Abandoned downloads may get cancelled

Downloading Content

NSURLConnection *connection = [asset downloadWithDelegate:myDelegate];

NKLibrary *library = [NKLibrary sharedLibrary];

for (NKAssetDownload *asset in [library downloadingAssets])

UPDATING

INFORMING

ORGANIZING

DOWNLOADING

42

Downloading ContentCompletion

• Success!-connectionDidFinishDownloading:destinationURL:

■ Destination is a temporary file■ Move to issue repository

[myIssue contentURL]

■ Process-[UIApplication beginTaskWithExpirationHandler:];

UPDATING

INFORMING

ORGANIZING

DOWNLOADING

43

Downloading contentDemo

44

Updating Your Newsstand Icon

Jon Drummond

45

Updating Your Newsstand IconShowing off your new content

• Part of getting new content is obtaining a new icon

• Once content is ready to view, show it off!■ Update your Newsstand icon■ Inform readers of new issues via badging

June 2011

INFORMING

ORGANIZING

DOWNLOADING

UPDATING

May 2011

46

Updating Your Newsstand IconUpdate your icon

• Publication covers play a huge role in the physical newsstand■ We want your icons to do the same here

• Your icon should represent your most recent content■ But don’t show it until your content is ready to read!

• Changes the appearance of your app in Newsstand and app switcher■ Overrides your UINewsstandIcon, not your standard app icon

INFORMING

ORGANIZING

DOWNLOADING

UPDATING

47

Updating Your Newsstand IconUpdate your icon

• Simple!-[UIApplication setNewsstandIconImage:(UIImage*)]

• Can be used while running in the background, so update whenever your content is ready

INFORMING

ORGANIZING

DOWNLOADING

UPDATING

48

Updating Your Newsstand IconBadge your app

• Badges in Newsstand have a revised look: “New” sash• Add a badge when a user has not yet opened a particular issue

■ Remove the badge once it has been read

INFORMING

ORGANIZING

DOWNLOADING

UPDATING

49

Updating Your Newsstand IconBadge your app

• Uses existing badge API-[UIApplication setApplicationIconBadgeNumber:(NSInteger)]

• As with normal badging...■ Non-zero value shows the sash■ Zero clears the sash

• The count is not shown, but it should track your unread issues

INFORMING

ORGANIZING

DOWNLOADING

UPDATING

50

Updating Your Newsstand Icon- (void)connectionDidFinishDownloading:(NSURLConnection*)connection

destinationURL:(NSURL*)destinationURL {

}

INFORMING

ORGANIZING

DOWNLOADING

UPDATING

51

Updating Your Newsstand Icon- (void)connectionDidFinishDownloading:(NSURLConnection*)connection

destinationURL:(NSURL*)destinationURL {// get issue content locationNKIssue *latestIssue = [[connection newsstandAssetDownload] issue];NSURL *issueURL = [[latestIssue contentURL] URLByAppendingPathComponent:...];

}

INFORMING

ORGANIZING

DOWNLOADING

UPDATING

52

Updating Your Newsstand Icon- (void)connectionDidFinishDownloading:(NSURLConnection*)connection

destinationURL:(NSURL*)destinationURL {// get issue content locationNKIssue *latestIssue = [[connection newsstandAssetDownload] issue];NSURL *issueURL = [[latestIssue contentURL] URLByAppendingPathComponent:...];

// move issue into place -- don’t forget to check errors!NSFileManager *fileManager = [NSFileManager defaultManager];[fileManager moveItemAtURL:destinationURL toURL:issueURL error:NULL];

}

INFORMING

ORGANIZING

DOWNLOADING

UPDATING

53

Updating Your Newsstand Icon- (void)connectionDidFinishDownloading:(NSURLConnection*)connection

destinationURL:(NSURL*)destinationURL {// get issue content locationNKIssue *latestIssue = [[connection newsstandAssetDownload] issue];NSURL *issueURL = [[latestIssue contentURL] URLByAppendingPathComponent:...];

// move issue into place -- don’t forget to check errors!NSFileManager *fileManager = [NSFileManager defaultManager];[fileManager moveItemAtURL:destinationURL toURL:issueURL error:NULL];

// get our new icon and update our app!UIImage *newIcon = [self getIconFromIssue:latestIssue]; // up to you

}

INFORMING

ORGANIZING

DOWNLOADING

UPDATING

54

Updating Your Newsstand Icon- (void)connectionDidFinishDownloading:(NSURLConnection*)connection

destinationURL:(NSURL*)destinationURL {// get issue content locationNKIssue *latestIssue = [[connection newsstandAssetDownload] issue];NSURL *issueURL = [[latestIssue contentURL] URLByAppendingPathComponent:...];

// move issue into place -- don’t forget to check errors!NSFileManager *fileManager = [NSFileManager defaultManager];[fileManager moveItemAtURL:destinationURL toURL:issueURL error:NULL];

// get our new icon and update our app!UIImage *newIcon = [self getIconFromIssue:latestIssue]; // up to youUIApplication *app = [UIApplication sharedApplication];[app setNewsstandIconImage:newIcon];[app setApplicationIconBadgeNumber:[app applicationIconBadgeNumber]+1];

}

INFORMING

ORGANIZING

DOWNLOADING

UPDATING

55

Updating your Newsstand iconDemo

56

Summary

• Becoming a Newsstand app is easy• Get content updates in the background• Use NewsstandKit to download and organize content• Update your Newsstand icon and badge to show off your content

57

Vicki MurleySafari Technology Evangelistvicki@apple.com

More Information

58

App Publishing with iTunes Connect PresidioThursday 10:15AM

Local and Push Notifications Pacific HeightsThursday 4:30PM

Related Sessions

Adopting Multitasking Russian HillThursday 4:30PM

59

Newsstand Lab Internet & Web Lab BThursday 2:00PM

Local and Push Notifications Lab Internet & Web Lab AFriday 9:00AM

Labs

App Publishing with iTunes Connect Lab Internet & Web Lab AThursday 2:00PM

60

Q&A

61

62

Recommended