building newsstand_apps

62
These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 504 Building Newsstand Apps Ben Nielsen iOS Application Engineering 1

Upload: hessel-van-tuinen

Post on 01-Nov-2014

1.531 views

Category:

Technology


1 download

DESCRIPTION

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

TRANSCRIPT

Page 1: Building newsstand_apps

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

Session 504

Building Newsstand Apps

Ben NielseniOS Application Engineering

1

Page 2: Building newsstand_apps

2

Page 3: Building newsstand_apps

3

Page 4: Building newsstand_apps

4

Page 5: Building newsstand_apps

5

Page 6: Building newsstand_apps

2222222

6

Page 7: Building newsstand_apps

NewsstandThe look

7

Page 8: Building newsstand_apps

The lookNewsstand

• Repository for publications

• Richer visual experience

• Icons reflect content

• iTunes Store integration

8

Page 9: Building newsstand_apps

NewsstandKit

• Push notification updates

• Content organization

• Background downloads

NewsstandKitNKLibraryNKIssue

NKAssetDownload

Your App

Foundation

UIKit

9

Page 10: Building newsstand_apps

What You’ll Learn

• Appearing in Newsstand

• Retrieving content

• Presenting content

10

Page 11: Building newsstand_apps

Appearing in Newsstand

Jon DrummondiOS Application Engineering

11

Page 12: Building newsstand_apps

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

Page 13: Building newsstand_apps

Time for an icon

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

Appearing in Newsstand

13

Page 14: Building newsstand_apps

14

Page 15: Building newsstand_apps

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

Page 16: Building newsstand_apps

Appearing in NewsstandStandard icons

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

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

16

Page 17: Building newsstand_apps

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>[email protected]</string>

...

</array>

17

Page 18: Building newsstand_apps

Newsstand icons

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

UINewsstandIcon

Appearing in Newsstand

CFBundlePrimaryIcon

18

Page 19: Building newsstand_apps

Appearing in NewsstandUpdating your Info.plist

<key>CFBundleIconFiles</key>

<array>

<string>Icon.png</string>

<string>[email protected]</string>

</array>

<key>CFBundleIcons</key>

<dict>New top-level key

Existing CFBundleIconFiles

Icon style key<key>CFBundlePrimaryIcon</key>

<dict>

</dict>

</dict>

19

Page 20: Building newsstand_apps

Appearing in NewsstandUpdating your Info.plist

<key>CFBundleIconFiles</key>

<array>

<string>Icon.png</string>

<string>[email protected]</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

Page 21: Building newsstand_apps

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

Page 22: Building newsstand_apps

Customizing your Newsstand iconAppearing in Newsstand

UINewsstandBindingEdgeLeftUINewsstandBindingEdgeRightUINewsstandBindingEdgeBottom

Fold

Stack

UINewsstandBindingTypeNewspaperUINewsstandBindingTypeMagazine

Staples Pages

22

Page 23: Building newsstand_apps

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

Page 24: Building newsstand_apps

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

Page 25: Building newsstand_apps

Creating a Newsstand AppDemo

25

Page 26: Building newsstand_apps

Handling Updates

Ben NielseniOS Application Engineering

26

Page 27: Building newsstand_apps

Retrieving and presenting content

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

Handling Updates

ORGANIZINGUPDATING

INFORMING

DOWNLOADING

27

Page 28: Building newsstand_apps

Informing the AppHandling Updates

28

Page 29: Building newsstand_apps

Informing the AppPush notifications

DOWNLOADING

ORGANIZINGUPDATING

INFORMING

29

Page 30: Building newsstand_apps

‘content-available’:1

Informing the AppNewsstand Push Notifications

• Registration TypeUIRemoteNotificationTypeNewsstandContentAvailability

• Payload Key{

‘aps’:{

}

}

• Once per day■ NSUserDefaults: @”NKDontThrottleNewsstandContentNotifications”

DOWNLOADING

ORGANIZINGUPDATING

INFORMING

30

Page 31: Building newsstand_apps

<key>UIBackgroundModes</key>

<array>

<string> </string>

</array>

newsstand-content

Informing the AppNewsstand Push Notifications

• Background mode

• Limited time-[UIApplication beginTaskWithExpirationHandler:]

DOWNLOADING

ORGANIZINGUPDATING

INFORMING

31

Page 32: Building newsstand_apps

Organizing issuesHandling Updates

32

Page 33: Building newsstand_apps

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

Page 34: Building newsstand_apps

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

Page 35: Building newsstand_apps

Downloading contentHandling Updates

35

Page 36: Building newsstand_apps

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

Page 37: Building newsstand_apps

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

Page 38: Building newsstand_apps

NSURLConnectionDownloadDelegate

[asset downloadWithDelegate:myDelegate];

• Implements NSURLConnectionDelegate■ Status■ Authentication■ Completion

• Modifications-connection:didReceiveData:

Downloading Content UPDATING

INFORMING

ORGANIZING

DOWNLOADING

NSURLConnectionDownloadDelegate

38

Page 39: Building newsstand_apps

Downloading ContentNSURLConnectionDownloadDelegate

[asset downloadWithDelegate:myDelegate];

• Implements NSURLConnectionDelegate■ Status■ Authentication■ Completion

• Modifications-connection:didWriteData:totalBytesWritten:expectedTotalBytesWritten:

-connectionDidResumeDownloading:totalBytesWritten:expectedTotalBytesWritten:

-connectionDidFinishLoading:

UPDATING

INFORMING

ORGANIZING

DOWNLOADING

39

Page 40: Building newsstand_apps

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

Page 41: Building newsstand_apps

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

Page 42: Building newsstand_apps

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

Page 43: Building newsstand_apps

Downloading ContentCompletion

• Success!-connectionDidFinishDownloading:destinationURL:

■ Destination is a temporary file■ Move to issue repository

[myIssue contentURL]

■ Process-[UIApplication beginTaskWithExpirationHandler:];

UPDATING

INFORMING

ORGANIZING

DOWNLOADING

43

Page 44: Building newsstand_apps

Downloading contentDemo

44

Page 45: Building newsstand_apps

Updating Your Newsstand Icon

Jon Drummond

45

Page 46: Building newsstand_apps

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

Page 47: Building newsstand_apps

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

Page 48: Building newsstand_apps

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

Page 49: Building newsstand_apps

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

Page 50: Building newsstand_apps

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

Page 51: Building newsstand_apps

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

destinationURL:(NSURL*)destinationURL {

}

INFORMING

ORGANIZING

DOWNLOADING

UPDATING

51

Page 52: Building newsstand_apps

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

Page 53: Building newsstand_apps

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

Page 54: Building newsstand_apps

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

Page 55: Building newsstand_apps

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

Page 56: Building newsstand_apps

Updating your Newsstand iconDemo

56

Page 57: Building newsstand_apps

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

Page 58: Building newsstand_apps

Vicki MurleySafari Technology [email protected]

More Information

58

Page 59: Building newsstand_apps

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

Page 60: Building newsstand_apps

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

Page 61: Building newsstand_apps

Q&A

61

Page 62: Building newsstand_apps

62