TopShelfContent doesn't update?

Hey all,


I've been having some trouble working with the TopShelf. I've been using the UIKit Catalog (tvOS)[1] sample project to learn how to work with TVServices, but I've encountered a problem. I cannot seem to update the TopShelf content. The documentation says that I should post the TVTopShelfItemsDidChangeNotification message but I'm unable to see any change happening in the TopShelf.


This is the code that's called:


import UIKit
import TVServices
----
----

    override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)       
        print("Before change: ")
        print(DataItem.sampleItems)
   
        DataItem.sampleItems = {
            return DataItem.Group.allGroups.flatMap { group -> [DataItem] in
                let itemCount: Int
           
                switch group {
                case .Scenery:
                    itemCount = 2
               
                case .Iceland:
                    itemCount = 2
               
                case .Lola:
                    itemCount = 2
               
                case .Baby:
                    itemCount = 2
                }
           
                return (1...itemCount).map { DataItem(group: group, number: $0) }
            }
            }()
   
        print("------------------------------------------------------------")
        print("After change")
        print(DataItem.sampleItems)
    print("NSNotificationCenter.defaultCenter().postNotificationName(TVTopShelfItemsDidChangeNotification, object: nil) is called")
        NSNotificationCenter.defaultCenter().postNotificationName(TVTopShelfItemsDidChangeNotification, object: nil)
}


and this is the log (slightly edited the original samples to decrease log size):


Before change:

[UIKitCatalog.DataItem(group: UIKitCatalog.DataItem.Group.Scenery, number: 1),

UIKitCatalog.DataItem(group: UIKitCatalog.DataItem.Group.Iceland, number: 1),

UIKitCatalog.DataItem(group: UIKitCatalog.DataItem.Group.Lola, number: 1),

UIKitCatalog.DataItem(group: UIKitCatalog.DataItem.Group.Baby, number: 1)]

------------------------------------------------------------

After change

[UIKitCatalog.DataItem(group: UIKitCatalog.DataItem.Group.Scenery, number: 1),

UIKitCatalog.DataItem(group: UIKitCatalog.DataItem.Group.Scenery, number: 2),

UIKitCatalog.DataItem(group: UIKitCatalog.DataItem.Group.Iceland, number: 1),

UIKitCatalog.DataItem(group: UIKitCatalog.DataItem.Group.Iceland, number: 2),

UIKitCatalog.DataItem(group: UIKitCatalog.DataItem.Group.Lola, number: 1),

UIKitCatalog.DataItem(group: UIKitCatalog.DataItem.Group.Lola, number: 2),

UIKitCatalog.DataItem(group: UIKitCatalog.DataItem.Group.Baby, number: 1),

UIKitCatalog.DataItem(group: UIKitCatalog.DataItem.Group.Baby, number: 2)]

NSNotificationCenter.defaultCenter().postNotificationName(TVTopShelfItemsDidChangeNotification, object: nil) is called


I haven't altered any project settings and the first samples do appear as expected (Iceland 1 and Lola 1), but after the code is called, nothing is changed. It still only shows Iceland 1 and Lola 1. I expected to see Iceland 1,2 and Lola 1,2. Am I missing something?


[1] https://developer.apple.com/library/prerelease/tvos/samplecode/UICatalogFortvOS/Introduction/Intro.html

You don't give enough context to determine which file exactly that you're adding that to. But given that you're overriding a UIViewController method, it must not be the right file.


You want to change ServiceProvider.swift in the UIKitCatalog Extension folder. The view controller classes are not compiled into the extension (nor should they be), which is where the Top Shelf content comes from. To change what appears in the top shelf, take a look at the sectionedTopShelfItems property, probably you want to tweak the calculation of dataItemSections.


As for the posting of the notification, you can do that from either the app or the extension. From the app, this would be while the app is running, and the user will see the changes [that the extension returns] when the user exits the app and goes back to the main menu. If you want the user to be able to change a setting or something in the app, and have that change reflected in top shelf (‡), then the app and extension have to do something like share preferences, and the extension look at the preferences. (‡ for example, perhaps the user logs in, and now you can show more customized things in the top shelf; or perhaps your app allows the user to select which items to show in the top shelf)


For experimentation, you could set up a 30 second timer in the ServiceProvider class, to change some new properties (like the count of the number of sections to return), (and change sectionedTopShelfItems to look at them to compute its value), and then post the notfiication.

Hi,


You confirm that the timer in ServiceProvider is just for DEBUG mode ? it's better to call sync request when we swicth to the app in the dock and


topShelfItems is called ?


See my post about similar question and tests : https://forums.developer.apple.com/message/74377#74377


Thank you so much.

TopShelfContent doesn't update?
 
 
Q