Post

Replies

Boosts

Views

Activity

Is it possible to have a custom light blend with environment light in RealityKit?
I was able to add a spotlight effect to my entities using ImageBasedLightComponent and the sample code. However, I noticed that whenever you set ImageBasedLightComponent the environmental lighting is completely turned off. Is it possible to merge them somehow? So imagine you have a toy in a the real world, and you shine a flashlight on it. The environment light should still have an effect right?
0
0
282
Feb ’24
Is it possible to change usdz objects inside a scene programmatically?
Let's say I've created a scene with 3 models inside side by side. Now upon user interaction, I'd like to change these models to another model (that is also in the same reality composer pro project). Is that possible? How can one do that? One way I can think of is to just load all the individual models in RealityView and then just toggle the opacity to show/hide the models. But this doesn't seem like the right way for performance/memory reasons. How do you swap in and out usdz models?
1
0
484
Feb ’24
Textfield works very weird in iOS 17, how to fix?
I have the following code working great in iOS16 TextField( "Describe...", text: Binding( get: { promptText }, set: { (newValue, _) in if let _ = newValue.lastIndex(of: "\n") { isFocused = false } else { promptText = newValue } } ), axis: .vertical ) but in iOS 17 it breaks. But it breaks in a very mysterious way. Firstly, the @ FocusState doesn't work. Setting it to false does not dismiss keyboard. Fine, but also what's weird is that when I press the done button, the new line gets added to the textField anyway, even if I don't set the newValue. What's going on?
1
1
510
Aug ’23
What is the best way for other ViewModel to get a reference to NavigationModel according to WWDC example?
In https://developer.apple.com/wwdc22/10054 it is shown that the best way to organize an iPad layout is by: struct TwoColumnContentView: View { @Binding var showExperiencePicker: Bool @EnvironmentObject private var navigationModel: NavigationModel var categories = Category.allCases var dataModel = DataModel.shared var body: some View { NavigationSplitView( columnVisibility: $navigationModel.columnVisibility ) { List( categories, selection: $navigationModel.selectedCategory ) { category in NavigationLink(category.localizedName, value: category) } .navigationTitle("Categories") .toolbar { ExperienceButton(isActive: $showExperiencePicker) } } detail: { NavigationStack(path: $navigationModel.recipePath) { RecipeGrid(category: navigationModel.selectedCategory) } } } } NavigationModel defined as final class NavigationModel: ObservableObject, Codable { @Published var selectedCategory: Category? @Published var recipePath: [Recipe] @Published var columnVisibility: NavigationSplitViewVisibility } But what happens when in a child view, it triggers off some action in some other ViewModel that needs to update the navigation stack? struct ChildViewModel { func childViewCalledAndDidSomething { //now I need to update recipePath, how? } }
0
0
552
Mar ’23
How to encode/decode [CKRecordZone.ID: CKServerChangeToken]?
public var zonesChangeToken: [CKRecordZone.ID: CKServerChangeToken]? { get { if(backingPreviousZonesChangeToken == nil) { guard let defaults: UserDefaults = UserDefaults(suiteName: CloudKitHandler.APP_GROUP_ID) else { return nil } guard let data = defaults.data(forKey: CloudKitHandler.CK_PREVIOUS_ZONES_CHANGE_TOKEN) else { return [CKRecordZone.ID: CKServerChangeToken]() } do { let unarchiver: NSKeyedUnarchiver = try NSKeyedUnarchiver(forReadingFrom: data) unarchiver.requiresSecureCoding = true backingPreviousZonesChangeToken = try unarchiver.decodeTopLevelObject() as? [CKRecordZone.ID: CKServerChangeToken] } catch { } } return backingPreviousZonesChangeToken } set(value) { backingPreviousZonesChangeToken = value guard let value = value else { return } guard let defaults: UserDefaults = UserDefaults(suiteName: CloudKitHandler.APP_GROUP_ID) else { return } let archiver: NSKeyedArchiver = NSKeyedArchiver(requiringSecureCoding: true) archiver.encode(value) archiver.finishEncoding() defaults.setValue(archiver.encodedData, forKey: CloudKitHandler.CK_PREVIOUS_ZONES_CHANGE_TOKEN) } }I'm trying to encode/decode a dictionary of IDs and Tokens. But for some reason the decode always gives me a nil.How to fix?Error Domain=NSCocoaErrorDomain Code=4864 "value for key '$0' was of unexpected class 'NSDictionary'. Allowed classes are '(null)'." UserInfo={NSDebugDescription=value for key '$0' was of unexpected class 'NSDictionary'. Allowed classes are '(null)'.}
1
0
647
Feb ’20
Change token in Cloudkit is not giving me all transactions, please help!
Let's say the sequence of events go like thisI have token A for a Shared DatabaseRecords get created in Shared DatabaseI fetch for changes and downloaded new records, gets token BI accepted a new share in the same zone and databaseI take the new record (NEW_REC) from inside CKShare.Metadata and saves it, but I dont have a new tokenBut now NEW_REC gets deleted by the sharerI then fetch for new changes for the zone and use token B, but CK will not let me know NEW_REC is deletedI tested this using the dashboard, so it has nothing to do with my code.Is this intentional? I'm thinking that the algorithm is designed to work like this because it thinks that from the perspective of token B, NEW_REC never existed? So why bother telling the client is deleted?But that doesn't taken into account that the new record came from metadata. I also wonder the same case if you did CKQuery to get new records, without using CKFetchRecordZoneChangesOperation do you suffer from the same problem?
0
0
487
Feb ’20
CKFetchRecordZoneChangesOperation breaks NSPersistentCloudKitContainer when called inside AppDelegate?
I'm trying to call CKFetchRecordZoneChangesOperation to get the latest changes from the shared database.But when I run that operation from inside didFinishLaunchingWithOptions, NSPersistentCloudKitContainer will break. It will save to coredata, but it will no longer sync to Cloudkit. It's as if it's paused. When I restart the app, the sync resumes.But if I call CKFetchRecordZoneChangesOperation later in the app lifecycle, say in viewDidLoad, everything works fine. Why is this?
1
0
446
Feb ’20
How to seed data with CloudKit?
I need to create some records in CloudKit for each user when they start an app.I can't just write a seed function that create records. Because when the user starts the app in two devices, they will each write their own seed record.What I want instead is for the first device to write to CloudKit gets to create the record. And then second device will simply update the values of those records no recreate them.How can I achieve this?
1
0
616
Feb ’20
Anyone here used UICloudSharingController? Delegate not working correctly
I'm completely stuck on this one 😟I'm just presenting a simple UICloudSharingController and set the delegate.Even though my itemThumbnailData and itemTitle delegate methods are called (I can see from debugger) but they take no effect.The controller still shows the screen with "Untitled" and place holder image. Why?Further more, cloudSharingControllerDidSaveShare is also not called back when I click save.
0
0
439
Feb ’20