How building simple activity hierarchy

Hi,


Last week we started to integrate ClassKit in our eductional apps for schools in The Netherlands. Despite the documentation is quite hard to understand the approach (especially the Apple team is expecting everything is nowdays written in Swift instead Obj C). But finally we got everything working fine except one thing:


How to setup a simple hierarchy in the CLSContext. The example on the video does not present a hierarchy and the example code in swift is not really setup for standard apps. Maybe we missed something in de docu and somebody can help us with the problem:


We would like to setup a chapter with an exercise. So the teacher hit our app icon, select the chapter and select finally one of the exercises. The setup of the model is totally static so we created from the documentations and demo the following function for setting up the activity model:


func publishContextIfNeeded(completion:((Error?) -> Void)? = nil) {

        if #available(iOS 11.4, *) {
            
            
            let chapter1 = CLSContext(type:.chapter, identifier: "chapter1", title:"Chapter 1")
            chapter1.displayOrder = 0
             
            let opdracht1 = CLSContext(type:.exercise, identifier: "K001001a", title:"Exercise 1: Mulitplications by 1")
            opdracht1.displayOrder = 0

            var contextToCreate: [String: CLSContext] = [
                chapter1.identifier : chapter1]
            
            var contextToCreate2: [String: CLSContext] = [
                chapter1.identifier : chapter1,
                opdracht1.identifier : opdracht1]
            
            //get the parent context
            let parent = CLSDataStore.shared.mainAppContext
            
            //Issue a query by using CLSDataStore context matching identifier path
            let predicate = NSPredicate(format: "parent = %@",parent)
            CLSDataStore.shared.contexts(matching: predicate) { contexts, error in
                
                //Check if we already have a context created and remove if from our context array needing to be created
                for context in contexts {
                    
                    contextToCreate.removeValue(forKey: context.identifier)
                    contextToCreate2.removeValue(forKey: context.identifier)
                }
                
                //Go through all of the contexts that have not yet been created and add them as a child to our parent
                for (_, context) in contextToCreate {
                    parent.addChildContext(context)
                    
                }
                //Go through all of the contexts that have not yet been created and add them as a child to our parent
                for (_, context) in contextToCreate2 {
                    parent.addChildContext(context)
                    
                }
                
                //Save our changes
                CLSDataStore.shared.save { (error) in completion?(error)
                    
                    if let error = error {
                        print(error.localizedDescription)
                    }
                }
            }


        } else {
            // Fallback on earlier versions
        }
        
    

}


This code is working but the hierachy is missing in SchoolWork app and it presents everything on the same level. Hopefully someone can help us, we tried many ideas but none are working.


Kees

Replies

I posted here about a demo project (Obj-C) I put on github a little while back. In it, I show how to generate a hierarchical context tree (or at least how I do it).


Here's the link again: https://github.com/pkclsoft/ClassKitIntegration.git


Cheers

thanks, your demo saved me a lot of time and I got it working. Should be part of the Apple documentation. (my opinion). Did you find a way how you can send the student back to Schoolwork app screen after finishing the exercise?

You're welcome; I'm glad it was helpful.


No, I've not tried to direct the student back to the Schoolwork app automatically. There may be a URL that we can "open" that will trigger the Schoolwork app to open. I'm wondering if there is a documented URL scheme that can be used this way.


@Malonicus, are you able to shed any light on this?

I tried to follow the standard way to call the Schoolwork app like com.apple.schoolwork but it doesn't do anything. I think it would be great to finish the workflow back in the schoolwork app and see the registered results and give the task the status finished instead using the home button.


@Malonicus

Is there a possibilty to call the schoolwork app from another app?