Post

Replies

Boosts

Views

Activity

On Demand Resources does not show an error
I am integrating On Demand Resources into my Unity game. The resources install without any problems if the internet connection is stable: all resources are installed. While testing various scenarios without an internet connection, I encountered the following problem: if I turn off the internet during installation, I don't get any error messages, but if I turn the internet back on, the download no longer continues (and I still don't get an error). If I reopen the application with a stable internet connection, the download will always be at 0%. Please tell me what I am doing wrong. #import "Foundation/Foundation.h" #if ENABLE_IOS_ON_DEMAND_RESOURCES #import "Foundation/NSBundle.h" #endif #include <string.h> struct CustomOnDemandResourcesRequestData; typedef void (*CustomOnDemandResourcesRequestCompleteHandler)(struct CustomOnDemandResourcesRequestData* handler, const char* error); #if ENABLE_IOS_ON_DEMAND_RESOURCES struct CustomOnDemandResourcesRequestData { NSBundleResourceRequest* request; }; extern "C" CustomOnDemandResourcesRequestData* CustomOnDemandResourcesCreateRequest(const char* const* tags, int tagCount, CustomOnDemandResourcesRequestCompleteHandler handler) { NSMutableArray* tagArray = [NSMutableArray array]; for (int i = 0; i < tagCount; i++) { const char* tag = tags[i]; if (tag != NULL) { [tagArray addObject:[NSString stringWithUTF8String:tag]]; } } NSSet* tagSet = [NSSet setWithArray:tagArray]; CustomOnDemandResourcesRequestData* data = new CustomOnDemandResourcesRequestData(); data->request = [[NSBundleResourceRequest alloc] initWithTags:tagSet]; [data->request beginAccessingResourcesWithCompletionHandler:^(NSError* error) { dispatch_async(dispatch_get_main_queue(), ^{ const char* errorMessage = error ? [[error localizedDescription] UTF8String] : NULL; handler(data, errorMessage); }); }]; return data; } extern "C" void CustomOnDemandResourcesRelease(CustomOnDemandResourcesRequestData* data) { [data->request endAccessingResources]; delete data; } extern "C" float CustomOnDemandResourcesGetProgress(CustomOnDemandResourcesRequestData* data) { return data->request.progress.fractionCompleted; } extern "C" float CustomOnDemandResourcesGetLoadingPriority(CustomOnDemandResourcesRequestData* data) { float priority = (float)data->request.loadingPriority; return priority; } extern "C" void CustomOnDemandResourcesSetLoadingPriority(CustomOnDemandResourcesRequestData* data, float priority) { if (priority < 0.0f) priority = 0.0f; if (priority > 1.0f) data->request.loadingPriority = NSBundleResourceRequestLoadingPriorityUrgent; else data->request.loadingPriority = (double)priority; } extern "C" const char* CustomOnDemandResourcesGetResourcePath(CustomOnDemandResourcesRequestData * data, const char* resource) { NSString* resourceStr = [NSString stringWithUTF8String: resource]; NSString* path = [[data->request bundle] pathForResource: resourceStr ofType: nil]; if (path == nil) { return NULL; // или другое значение по умолчанию } const char* result = strdup([path UTF8String]); // копируем строку return result; // в C# нужно будет освободить память } extern "C" void CustomOnDemandResourcesFreeString(const char* str) { free((void*)str); } #else // ENABLE_IOS_ON_DEMAND_RESOURCES struct CustomOnDemandResourcesRequestData { }; extern "C" CustomOnDemandResourcesRequestData* CustomOnDemandResourcesCreateRequest(const char* const* tags, int tagCount, CustomOnDemandResourcesRequestCompleteHandler handler) { CustomOnDemandResourcesRequestData* data = new CustomOnDemandResourcesRequestData(); if (handler) handler(handlerData, NULL); return data; } extern "C" void CustomOnDemandResourcesRelease(CustomOnDemandResourcesRequestData* data) { delete data; } extern "C" float CustomOnDemandResourcesGetProgress(CustomOnDemandResourcesRequestData* data) { return 0.0f; } extern "C" float CustomOnDemandResourcesGetLoadingPriority(CustomOnDemandResourcesRequestData* data) { return 0.0f; } extern "C" void CustomOnDemandResourcesSetLoadingPriority(CustomOnDemandResourcesRequestData* data, float priority) { } extern "C" const char* CustomOnDemandResourcesGetResourcePath(CustomOnDemandResourcesRequestData * data, const char* resource) { return NULL; } extern "C" void CustomOnDemandResourcesFreeString(const char* str) { } #endif // ENABLE_IOS_ON_DEMAND_RESOURCES
0
0
70
Oct ’25