forked from akai/readest
fix(ios): don't crash app init when Storefront region code is unavailable (#4291)
`getStorefrontRegionCode` rejects when `Storefront.current` is nil (unsigned simulator, signed-out device, StoreKit not yet ready, parental controls, etc.). The call sits in NativeAppService startup before `prepareBooksDir`, so an unhandled rejection here aborts the rest of init and surfaces as a top-level unhandledRejection in the webview console. Wrap the call in try/catch and treat failure as 'unknown region', leaving `storefrontRegionCode` null so downstream region-gated features degrade gracefully. Also guard against an empty resolve shape with optional chaining on `res?.regionCode`.
This commit is contained in:
@@ -492,9 +492,18 @@ export class NativeAppService extends BaseAppService {
|
||||
}
|
||||
if (this.isIOSApp) {
|
||||
this.isOnlineCatalogsAccessible = this.distChannel !== 'appstore';
|
||||
const res = await getStorefrontRegionCode();
|
||||
if (res.regionCode) {
|
||||
this.storefrontRegionCode = res.regionCode;
|
||||
try {
|
||||
const res = await getStorefrontRegionCode();
|
||||
if (res?.regionCode) {
|
||||
this.storefrontRegionCode = res.regionCode;
|
||||
}
|
||||
} catch (err) {
|
||||
// Storefront.current is nil on simulators without a signed-in
|
||||
// App Store account, and may also fail on real devices with no
|
||||
// StoreKit configuration. Treat as "unknown region" — we leave
|
||||
// storefrontRegionCode as null and let downstream features that
|
||||
// depend on region degrade gracefully.
|
||||
console.warn('[nativeAppService] getStorefrontRegionCode failed:', err);
|
||||
}
|
||||
}
|
||||
await this.prepareBooksDir();
|
||||
|
||||
Reference in New Issue
Block a user