How to access USDZ schema at runtime - augmented-reality

From what I have read at https://developer.apple.com/documentation/arkit/usdz_schemas_for_ar it looks like you can do some great AR stuff like anchoring all from within the USDZ file itself.
I understand you can access this schema with python, but I would like to access the schema at runtime with Swift. Is that possible?

At the moment (February 2022) – no way!
Let's wait for AR USD schemas API.

Related

Is it possible to use Core Data in a document-based application?

I'm working on an iOS app that will need to save data onto files. I chose to go for a Document Based app, precisely an app based on a UIDocumentBrowserViewController so that I can easily save and load files from the system's Files app.
Since the data I need to save/load on a file is quite complex: big hierarchy of different objects, with meta-data, image files, etc. I'm wondering what is the best technology to use going forward.
I came across NSFileWrapperand its ability to save different files as one. And I could definitely use that. But I also saw UIManagedDocument and the ability to use Core Data in my project while maybe saving the content of the Core Data database (I know it's not quite a database, but you know what I mean) into a file that I could write somewhere in the File App.
Is this a behavior I can expect?
To reformulate: I'm wondering if I can read/write files through a UIDocumentBrowserViewController, with data described by a UIManagedDocument that works with Core Data.
Thank you in advance. 🙂
As you have discovered, UIManagedDocument is there for your kind of application. And it does feature methods to write and read additional content like the metadata or image files you have, within the document package.
That being said, I have never used UIManagedDocument, and have never seen it used by others. A quick search of GitHub finds only this one project with two contributors who wrote a wrapper around it in 2013. Also, there does not seem to be any sample code from Apple, and the remark in the the writeAdditionalContent(_:to:originalContentsURL:) documentation that Additional content is not supported on iCloud leaves me a little concerned, but maybe it's a good sign that the Core Data team knows where to draw the line.
I have used the macOS counterpart of UIManagedDocument, NSPersistentDocument. It is in a similar situation of not being used very much, but with many more known technical issues. So a few years ago I switched to BSManagedDocument, which purportedly mimics UIManagedDocument to support Core Data in all its modern glory. I have been happy with BSManagedDocument.
In summary, if I was in your situation, yes I would give UIManagedDocument a try. But don't be surprised if you need to use a DTS support incident or two during your development.

What is the best way to store dynamically changing data locally on iOS today?

My goal is to build a simple iOS app using Swift that will aggregate various types of data, from numerous sources, all with changing schema over time. It would also need to be able to handle something along the lines of 10’s of thousands of records to be saved. I am new to iOS programming when it comes to storing data locally. Obviously there are things like Local Storage and SQLite that could help me do this, but it seems like what I want is something more like a local MongoDB-like store that has been implemented in Swift. Is this what I should be looking for (because at this moment I have not found anything like this) or is there something I am missing or should be aware of in order to accomplish this?

Apple ResearchKit: how to extract information from ORKResult? First time programmer

I'm working on a simple ResearchKit app that has 20 survey questions, or ORKSteps. How do I get the answers from a participant who submits the survey into a database?
My research has found ORKESerializer and SQLite as potential parts of the solution. I'm missing a big picture view of how these things can be integrated into a working solution.
Starting without knowledge of databases or data transfer from Swift, so any basic information would be very helpful.
How do I extract data from ORKResult using Swift?
Where do I extract the data to? Or, what's the standard type of database for a small survey?
ResearchKit doesn't have any out-of-the-box solution for storing your results. Generally, it's the task of the developer to go through the ORKResult hierarchy and either persist the processed results for later access or send them to a remote server.
You have several options here:
Use NSCoding to store the vanilla ORKTaskResult (with their ORKResult children). This way you can recreate the whole ORKTaskResult hierarchy at later time to inspect or process it.
Use ORKESerializer (as you guessed) to serialize ORKResults into the JSON format. ORKESerializer is currently included as part of ORKTest's unit tests, and it's not documented very well. It's possible that it will be moved to ResearchKit proper in the future, but it's completely usable right now. The JSON format is particularly useful if you want to send your results to any remote server of your own.
You can manually iterate through ORKResults and convert them into objects that are suitable for storing, or into database records. As you said, you could persist them using SQLite; or other database of your choice; or Core Data.
To sum up, there's no recommended or standard method for persisting results, it depends on your needs.
You can also have a look at the official open sourced RK apps. I think they make use of the AppCore library (which sits on top of the ResearchKit) to store the task results (and also use the Sage Bridge to send the results to Sage's servers). But that may be overboard if your needs are simpler.
I suggest that you run the sample ORKCatalog app and then inspect the ORKTaskResult hierarchy (you can do that within the app itself). You'll get an idea of how the result hierarchy looks.
I do not have experience with the Research Kit but as a database you could use sqlite. stephencelis has made a great wrapper for swift which you can use.

How to save modified tilemap for level editor app

I'm making a map editor app for iOS. I can't seem to find any information on how to save a modified tilemap, though. I'm using cocos2d-v3 for my framework.
Does someone have any ideas on how this is done?
Thanks
You could port the TMX writer of Kobold Kit: https://github.com/KoboldKit/KoboldKit/tree/master/KoboldKit/KoboldKitFree/Framework/TilemapModel/TMX
It actually originates from the KoboldTouch project for cocos2d-iphone, dependencies on the engine is minimal for the entire tilemap model. However there's no renderer for this model available for cocos2d (except in KoboldTouch), and cocos2d's own renderer does not retain all of the tmx information in memory, and certainly not in a way that makes it easy to write back.
You should be able to use the TMXGenerator class for this. It was written specifically to do that kind of thing. It's a little dated (pre v3, I haven't tried it with the new source), but it will get you most, if not all, of what you need.
https://github.com/slycrel/cocos2d-iphone-extensions/tree/develop/Extensions/TMXGenerator

iOS Map Kit Locations read from database

I have been tasked with creating an iPhone application for a client.
I have some coding experience but only in C# so it doesn't really help here but other than that I am a complete novice on iPhone coding.
What I am trying to accomplish is to get some form of store locator on a map.
I have successfully added the map, get the user location with it zooming into the user. I have added 2 annotations (Which I believe the the best way to go about showing locations on the map).
I have 2 queries that I need help with, What is the best way to go about listing the stores in some form of database. XML, PList, .sql etc... (this would also need to be read from the web as it would need to be easily edited as new stores would be added a lot). Is it possible to loop through the database and dynamically add the stores onto the map within a location of the user?
I am not asking anyone to write any code for me, I am just asking for some help as I have googled the hell out of this and cant seem to find anything that helps.
Any help would be much appreciated,
Thanks
In terms of your potential formats for saving these locations, you options include:
XML/JSON are good formats for exchanging data with a remote server, but less ideal for a local database (though they theoretically could be used for that purpose). JSON is marginally easier to deal with (using NSJSONSerialization), but XML can be relatively easily parsed, too (using, for example, NSXMLParser). If you're doing network operations, I also heartily recommend looking at AFNetworking, which offers some nice advantages over the standard NSURLConnection. This, of course, presumes that you have written a web service on your server to deliver the necessary JSON or XML feed.
Plist is a fine, simple format if you want to save a short, local list of locations on iOS devices. Saving data to a plist is as simple as calling writeToFile method for your NSDictionary or NSArray and reading data is done via [NSDictionary dictionaryWithContentsOfFile:filename] or [NSArray arrayWithContentsOfFile:filename].
Core Data is a good, iOS-specific format for larger databases. It's probably the preferred iOS mechanism for dealing with persistent objects, but is an order of magnitude more complicated than plists.
SQLite is also a good database format if you're thinking about a structure that lends itself towards larger database, but also which lends itself towards eventual rollout to multiple platforms (e.g. both Android and iOS). If you decide to go SQLite route, consider an Objective-C wrapper (such as FMDB), which will simplify your life greatly.
Implicit in all of the above discussion is that, yes, you certainly can write code that iterates through your database and/or model data structures, extracting the necessary location information, and dynamically add annotations to your map. The Location Awareness Programming Guide should help introduce you to some of the MapKit related features.
"Is it possible to loop through the database and dynamically add the stores onto the map within a location of the user?"
Yes. Just as you have created those first two annotations, you now need to create more annotations in a loop. The only additional info you might need is that once you have added an annotation to the map it will stay there until you remove it. So you don't need to maintain your own list of annotations unless you want to do something else with it. Just fire and forget. So now your question comes down to how to loop through data from your chosen data source in Objective-C and not MapKit specific.
I know this is old but if anyone else comes across this like I did, you can use tmysqlkit by tanmay bakshi to read and write directly to a mysql database on a server.
Best,
Sam

Resources