Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.0+4

* Ensures that `NSError` instances with an unexpected value for the `userInfo` field don't crash the app, but send an explanatory message instead.

## 0.3.0+3

* Implements transaction caching for StoreKit ensuring transactions are delivered to the Flutter client.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,56 @@ - (void)testError {
XCTAssertEqualObjects(map, self.errorMap);
}

- (void)testErrorWithNSNumberAsUserInfo {
NSError *error = [NSError errorWithDomain:SKErrorDomain code:3 userInfo:@{@"key" : @42}];
NSDictionary *expectedMap =
@{@"domain" : SKErrorDomain, @"code" : @3, @"userInfo" : @{@"key" : @42}};
NSDictionary *map = [FIAObjectTranslator getMapFromNSError:error];
XCTAssertEqualObjects(expectedMap, map);
}

- (void)testErrorWithMultipleUnderlyingErrors {
NSError *underlyingErrorOne = [NSError errorWithDomain:SKErrorDomain code:2 userInfo:nil];
NSError *underlyingErrorTwo = [NSError errorWithDomain:SKErrorDomain code:1 userInfo:nil];
NSError *mainError = [NSError
errorWithDomain:SKErrorDomain
code:3
userInfo:@{@"underlyingErrors" : @[ underlyingErrorOne, underlyingErrorTwo ]}];
NSDictionary *expectedMap = @{
@"domain" : SKErrorDomain,
@"code" : @3,
@"userInfo" : @{
@"underlyingErrors" : @[
@{@"domain" : SKErrorDomain, @"code" : @2, @"userInfo" : @{}},
@{@"domain" : SKErrorDomain, @"code" : @1, @"userInfo" : @{}}
]
}
};
NSDictionary *map = [FIAObjectTranslator getMapFromNSError:mainError];
XCTAssertEqualObjects(expectedMap, map);
}

- (void)testErrorWithUnsupportedUserInfo {
NSError *error = [NSError errorWithDomain:SKErrorDomain
code:3
userInfo:@{@"user_info" : [[NSObject alloc] init]}];
NSDictionary *expectedMap = @{
@"domain" : SKErrorDomain,
@"code" : @3,
@"userInfo" : @{
@"user_info" : [NSString
stringWithFormat:
@"Unable to encode native userInfo object of type %@ to map. Please submit an "
@"issue at https://github.com/flutter/flutter/issues/new with the title "
@"\"[in_app_purchase_storekit] Unable to encode userInfo of type %@\" and add "
@"reproduction steps and the error details in the description field.",
[NSObject class], [NSObject class]]
}
};
NSDictionary *map = [FIAObjectTranslator getMapFromNSError:error];
XCTAssertEqualObjects(expectedMap, map);
}

- (void)testLocaleToMap {
if (@available(iOS 10.0, *)) {
NSLocale *system = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,43 @@ + (NSDictionary *)getMapFromNSError:(NSError *)error {
if (!error) {
return nil;
}

NSMutableDictionary *userInfo = [NSMutableDictionary new];
for (NSErrorUserInfoKey key in error.userInfo) {
id value = error.userInfo[key];
if ([value isKindOfClass:[NSError class]]) {
userInfo[key] = [FIAObjectTranslator getMapFromNSError:value];
} else if ([value isKindOfClass:[NSURL class]]) {
userInfo[key] = [value absoluteString];
} else {
userInfo[key] = value;
}
userInfo[key] = [FIAObjectTranslator encodeNSErrorUserInfo:value];
}
return @{@"code" : @(error.code), @"domain" : error.domain ?: @"", @"userInfo" : userInfo};
}

+ (id)encodeNSErrorUserInfo:(id)value {
if ([value isKindOfClass:[NSError class]]) {
return [FIAObjectTranslator getMapFromNSError:value];
} else if ([value isKindOfClass:[NSURL class]]) {
return [value absoluteString];
} else if ([value isKindOfClass:[NSNumber class]]) {
return value;
} else if ([value isKindOfClass:[NSString class]]) {
return value;
} else if ([value isKindOfClass:[NSArray class]]) {
NSMutableArray *errors = [[NSMutableArray alloc] init];
for (id error in value) {
[errors addObject:[FIAObjectTranslator encodeNSErrorUserInfo:error]];
}
return errors;
} else {
return [NSString
stringWithFormat:
@"Unable to encode native userInfo object of type %@ to map. Please submit an issue at "
@"https://github.com/flutter/flutter/issues/new with the title "
@"\"[in_app_purchase_storekit] "
@"Unable to encode userInfo of type %@\" and add reproduction steps and the error "
@"details in "
@"the description field.",
[value class], [value class]];
}
}

+ (NSDictionary *)getMapFromSKStorefront:(SKStorefront *)storefront {
if (!storefront) {
return nil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: in_app_purchase_storekit
description: An implementation for the iOS platform of the Flutter `in_app_purchase` plugin. This uses the StoreKit Framework.
repository: https://github.com/flutter/plugins/tree/main/packages/in_app_purchase/in_app_purchase_storekit
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+in_app_purchase%22
version: 0.3.0+3
version: 0.3.0+4

environment:
sdk: ">=2.14.0 <3.0.0"
Expand Down