From e27ea3a5f50e5c0dcb7682b834976cd481a6fce8 Mon Sep 17 00:00:00 2001 From: nitrag Date: Tue, 10 Mar 2026 17:53:36 -0400 Subject: [PATCH] Expose Offline Region ID property on MLNOfflinePack for Darwin/iOS (#4161) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- platform/darwin/src/MLNOfflinePack.h | 12 ++++++++++++ platform/darwin/src/MLNOfflinePack.mm | 8 ++++++++ platform/darwin/test/MLNOfflinePackTests.mm | 1 + platform/darwin/test/MLNOfflineStorageTests.mm | 8 ++++++++ 4 files changed, 29 insertions(+) diff --git a/platform/darwin/src/MLNOfflinePack.h b/platform/darwin/src/MLNOfflinePack.h index 567c65e35..f0f7301c0 100644 --- a/platform/darwin/src/MLNOfflinePack.h +++ b/platform/darwin/src/MLNOfflinePack.h @@ -121,6 +121,18 @@ typedef struct __attribute__((objc_boxable)) MLNOfflinePackProgress { MLN_EXPORT @interface MLNOfflinePack : NSObject +/** + The unique identifier of the offline region associated with this pack. + + This identifier is an auto-incrementing value assigned by the offline database + when the region is created. It is stable across application launches and can be + used to distinguish between different offline packs. + + The value is `nil` for packs that have not yet been saved to the database. In + Swift, this property is typed as `NSNumber?`. + */ +@property (nonatomic, readonly, nullable) NSNumber *regionId; + /** The region for which the pack manages resources. */ diff --git a/platform/darwin/src/MLNOfflinePack.mm b/platform/darwin/src/MLNOfflinePack.mm index 2adb4715a..8b3b4d53d 100644 --- a/platform/darwin/src/MLNOfflinePack.mm +++ b/platform/darwin/src/MLNOfflinePack.mm @@ -92,6 +92,14 @@ private: @"MLNOfflinePack was not invalided prior to deallocation."); } +- (nullable NSNumber *)regionId { + if (_state == MLNOfflinePackStateInvalid || !_mbglOfflineRegion) { + return nil; + } + + return @(_mbglOfflineRegion->getID()); +} + - (id)region { MLNAssertOfflinePackIsValid(); diff --git a/platform/darwin/test/MLNOfflinePackTests.mm b/platform/darwin/test/MLNOfflinePackTests.mm index aa0752317..1099e128d 100644 --- a/platform/darwin/test/MLNOfflinePackTests.mm +++ b/platform/darwin/test/MLNOfflinePackTests.mm @@ -16,6 +16,7 @@ invalidPack.state, MLNOfflinePackStateInvalid, @"Offline pack should be invalid when initialized independently of MLNOfflineStorage."); + XCTAssertNil(invalidPack.regionId, @"Invalid offline pack should return nil regionID."); XCTAssertThrowsSpecificNamed( invalidPack.region, NSException, MLNInvalidOfflinePackException, @"Invalid offline pack should raise an exception when accessing its region."); diff --git a/platform/darwin/test/MLNOfflineStorageTests.mm b/platform/darwin/test/MLNOfflineStorageTests.mm index 741686d9d..147896d10 100644 --- a/platform/darwin/test/MLNOfflineStorageTests.mm +++ b/platform/darwin/test/MLNOfflineStorageTests.mm @@ -752,6 +752,14 @@ XCTAssertEqual([MLNOfflineStorage sharedOfflineStorage].packs.count, countOfPacks + 1, @"Adding contents of sideload_sat.db should add one pack."); + MLNOfflinePack *lastPack = + [MLNOfflineStorage sharedOfflineStorage].packs.lastObject; + XCTAssertNotNil(lastPack, @"Pack should exist after adding contents."); + XCTAssertNotNil(lastPack.regionId, + @"Region ID should not be nil after a pack is added."); + XCTAssertGreaterThan( + lastPack.regionId.longLongValue, 0, + @"Region ID should be greater than 0 after a pack is added."); }]; // Invalid database type