From aa1a28643fa5fcc135e3084196fec98f7c4f00f6 Mon Sep 17 00:00:00 2001 From: Jacob King Date: Thu, 30 May 2019 11:19:50 +0100 Subject: [PATCH 1/4] Stage one of SDK changes to support raw data. --- DigiMeSDK.podspec | 12 +- .../Classes/Callbacks/DMEClientCallbacks.h | 3 +- .../Callbacks/DMEClientDownloadDelegate.h | 1 - DigiMeSDK/Core/Classes/DMEClient.m | 10 +- .../Core/Classes/DMEClientConfiguration.m | 4 +- DigiMeSDK/Core/Classes/DMEDataUnpacker.h | 4 +- DigiMeSDK/Core/Classes/DMEDataUnpacker.m | 9 +- .../Core/Classes/Entities/CADataRequest.h | 4 + DigiMeSDK/Core/Classes/Entities/CAFile.h | 55 ------ DigiMeSDK/Core/Classes/Entities/CAFile.m | 55 ------ DigiMeSDK/Core/Classes/Entities/CAFile.swift | 179 ++++++++++++++++++ .../Classes/Entities/CAFileMetadata.swift | 45 +++++ DigiMeSDK/Core/Classes/Entities/CASession.h | 3 +- DigiMeSDK/Core/Classes/Errors/NSError+SDK.m | 3 + README.md | 25 ++- 15 files changed, 280 insertions(+), 132 deletions(-) delete mode 100755 DigiMeSDK/Core/Classes/Entities/CAFile.h delete mode 100755 DigiMeSDK/Core/Classes/Entities/CAFile.m create mode 100644 DigiMeSDK/Core/Classes/Entities/CAFile.swift create mode 100644 DigiMeSDK/Core/Classes/Entities/CAFileMetadata.swift diff --git a/DigiMeSDK.podspec b/DigiMeSDK.podspec index 45c7f0681..bc03f2575 100755 --- a/DigiMeSDK.podspec +++ b/DigiMeSDK.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "DigiMeSDK" - s.version = "2.4.2" + s.version = "2.5" s.summary = "digi.me iOS Consent Access SDK" s.homepage = "https://github.com/digime/digime-sdk-ios" s.license = { :type => "MIT", :file => "LICENSE" } @@ -9,7 +9,7 @@ Pod::Spec.new do |s| s.platform = :ios, "10.0" s.dependency "Brotli" s.dependency "GZIP" - + s.swift_version = "4.2" s.source = { :git => "https://github.com/digime/digime-sdk-ios.git", :branch => s.version, @@ -19,7 +19,7 @@ Pod::Spec.new do |s| s.default_subspec = 'Core' s.subspec 'Core' do |ss| - ss.source_files = "DigiMeSDK/Core/Classes/**/*.{h,m}", "DigiMeSDK/DigiMeSDK.h" + ss.source_files = "DigiMeSDK/Core/Classes/**/*.{h,m,swift}", "DigiMeSDK/DigiMeSDK.h" ss.resources = ["DigiMeSDK/Core/Assets/*.{der}"] ss.frameworks = "Foundation", "UIKit", "CoreGraphics", "Security", "StoreKit" ss.private_header_files = 'DigiMeSDK/Core/Classes/Network/*.h', @@ -31,7 +31,7 @@ Pod::Spec.new do |s| end s.subspec 'Postbox' do |ss| - ss.source_files = "DigiMeSDK/Postbox/Classes/**/*.{h,m}" + ss.source_files = "DigiMeSDK/Postbox/Classes/**/*.{h,m,swift}" ss.frameworks = "Foundation", "UIKit" ss.private_header_files = 'DigiMeSDK/Core/Classes/DMEPostboxManager.h' ss.xcconfig = { 'OTHER_CFLAGS' => '$(inherited) -DDigiMeSDKPostbox' } @@ -39,13 +39,13 @@ Pod::Spec.new do |s| end s.subspec 'Repository' do |ss| - ss.source_files = "DigiMeSDK/Repository/Classes/**/*.swift" + ss.source_files = "DigiMeSDK/Repository/Classes/**/*.{h,m,swift}" ss.frameworks = "Foundation" ss.dependency "DigiMeSDK/Core" end s.subspec 'GuestConsent' do |ss| - ss.source_files = "DigiMeSDK/GuestConsent/Classes/**/*.{h,m}" + ss.source_files = "DigiMeSDK/GuestConsent/Classes/**/*.{h,m,swift}" ss.resources = ["DigiMeSDK/Core/Assets/*.xcassets"] ss.frameworks = "Foundation", "UIKit" ss.private_header_files = 'DigiMeSDK/GuestConsent/Classes/DMEGuestConsentManager.h' diff --git a/DigiMeSDK/Core/Classes/Callbacks/DMEClientCallbacks.h b/DigiMeSDK/Core/Classes/Callbacks/DMEClientCallbacks.h index 4788a4cbc..5b53cb64e 100755 --- a/DigiMeSDK/Core/Classes/Callbacks/DMEClientCallbacks.h +++ b/DigiMeSDK/Core/Classes/Callbacks/DMEClientCallbacks.h @@ -8,12 +8,11 @@ #import "CASession.h" #import "CAFiles.h" -#import "CAFile.h" #import "CAAccounts.h" #pragma once -@class CAPostbox; +@class CAPostbox, CAFile; NS_ASSUME_NONNULL_BEGIN diff --git a/DigiMeSDK/Core/Classes/Callbacks/DMEClientDownloadDelegate.h b/DigiMeSDK/Core/Classes/Callbacks/DMEClientDownloadDelegate.h index b140f5890..e7491c243 100644 --- a/DigiMeSDK/Core/Classes/Callbacks/DMEClientDownloadDelegate.h +++ b/DigiMeSDK/Core/Classes/Callbacks/DMEClientDownloadDelegate.h @@ -13,7 +13,6 @@ #import "NSError+API.h" #import "CAAccounts.h" #import "CAFiles.h" -#import "CAFile.h" #pragma once diff --git a/DigiMeSDK/Core/Classes/DMEClient.m b/DigiMeSDK/Core/Classes/DMEClient.m index 724f1e2e4..62d5bd233 100755 --- a/DigiMeSDK/Core/Classes/DMEClient.m +++ b/DigiMeSDK/Core/Classes/DMEClient.m @@ -16,6 +16,7 @@ #import "DMEAuthorizationManager.h" #import "DMEClient+Private.h" #import "DMEDataUnpacker.h" +#import @implementation DMEClient @synthesize privateKeyHex = _privateKeyHex; @@ -300,7 +301,7 @@ - (void)getFileWithId:(NSString *)fileId completion:(FileContentCompletionBlock) if (completion) { - CAFile *file = [[CAFile alloc] initWithFileId:fileId]; + CAFile *file = [[CAFile alloc] initWithFileId:fileId fileContent:[NSData data] fileMetadata:nil]; completion(file, error); } else if ([self.downloadDelegate respondsToSelector:@selector(fileRetrieveFailed:error:)]) @@ -352,10 +353,11 @@ - (void)processFileData:(NSData *)data fileId:(NSString *)fileId completion:(Fil { CAFile *file; NSError *error; - NSData *unpackedData = [DMEDataUnpacker unpackData:data error:&error]; + CAFileMetadata *metadata; + NSData *unpackedData = [DMEDataUnpacker unpackData:data resolvedMetadata:&metadata error:&error]; if (unpackedData != nil) { - file = [CAFile deserialize:unpackedData fileId:fileId error:&error]; + file = [[CAFile alloc] initWithFileId:fileId fileContent:unpackedData fileMetadata:metadata]; } dispatch_async(dispatch_get_main_queue(), ^{ @@ -433,7 +435,7 @@ - (void)getAccountsWithCompletion:(AccountsCompletionBlock)completion CAAccounts *accounts; NSError *error; - NSData *unpackedData = [DMEDataUnpacker unpackData:data error:&error]; + NSData *unpackedData = [DMEDataUnpacker unpackData:data resolvedMetadata:NULL error:&error]; if (unpackedData != nil) { accounts = [CAAccounts deserialize:unpackedData error:&error]; diff --git a/DigiMeSDK/Core/Classes/DMEClientConfiguration.m b/DigiMeSDK/Core/Classes/DMEClientConfiguration.m index 5b0295878..2a1c97f79 100755 --- a/DigiMeSDK/Core/Classes/DMEClientConfiguration.m +++ b/DigiMeSDK/Core/Classes/DMEClientConfiguration.m @@ -61,11 +61,11 @@ - (NSString *)baseUrl } } - NSString *domain = dict[@"DME_DOMAIN"] ?: @"digi.me"; + NSString *domain = dict[@"DME_DOMAIN"] ?: @"integration.devdigi.me"; _baseUrl = [NSString stringWithFormat:@"https://api.%@/", domain]; } - return _baseUrl; + return @"https://api.integration.devdigi.me/"; } @end diff --git a/DigiMeSDK/Core/Classes/DMEDataUnpacker.h b/DigiMeSDK/Core/Classes/DMEDataUnpacker.h index 701c1a1e9..0bebfdbc7 100644 --- a/DigiMeSDK/Core/Classes/DMEDataUnpacker.h +++ b/DigiMeSDK/Core/Classes/DMEDataUnpacker.h @@ -10,6 +10,8 @@ NS_ASSUME_NONNULL_BEGIN +@class CAFileMetadata; + @interface DMEDataUnpacker : NSObject /** @@ -19,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN @param error The optional error which is populated if unpacking fails @return Unpacked data if successful, otherwise nil */ -+ (nullable NSData *)unpackData:(NSData *)data error:(NSError * _Nullable __autoreleasing *)error; ++ (nullable NSData *)unpackData:(NSData *)data resolvedMetadata:(CAFileMetadata * _Nullable __autoreleasing *)resolvedMetadata error:(NSError * _Nullable __autoreleasing *)error; @end diff --git a/DigiMeSDK/Core/Classes/DMEDataUnpacker.m b/DigiMeSDK/Core/Classes/DMEDataUnpacker.m index 9da0c8294..28327d994 100644 --- a/DigiMeSDK/Core/Classes/DMEDataUnpacker.m +++ b/DigiMeSDK/Core/Classes/DMEDataUnpacker.m @@ -10,10 +10,11 @@ #import "DMECompressor.h" #import "DMEDataUnpacker.h" #import "NSError+SDK.h" +#import @implementation DMEDataUnpacker -+ (nullable NSData *)unpackData:(NSData *)data error:(NSError * _Nullable __autoreleasing *)error ++ (nullable NSData *)unpackData:(NSData *)data resolvedMetadata:(CAFileMetadata * _Nullable __autoreleasing *)resolvedMetadata error:(NSError * _Nullable __autoreleasing *)error { NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:error]; @@ -23,6 +24,12 @@ + (nullable NSData *)unpackData:(NSData *)data error:(NSError * _Nullable __auto return nil; } + NSDictionary *metadataJSON = json[@"fileMetadata"]; + if (metadataJSON) + { + *resolvedMetadata = [CAFileMetadata metadataFromJSON:metadataJSON]; + } + id fileContent = json[@"fileContent"]; if (!fileContent) { diff --git a/DigiMeSDK/Core/Classes/Entities/CADataRequest.h b/DigiMeSDK/Core/Classes/Entities/CADataRequest.h index 42f8201eb..323951935 100644 --- a/DigiMeSDK/Core/Classes/Entities/CADataRequest.h +++ b/DigiMeSDK/Core/Classes/Entities/CADataRequest.h @@ -13,9 +13,13 @@ @protocol CADataRequest +NS_ASSUME_NONNULL_BEGIN + @property (nonatomic, strong, nullable) NSArray *timeRanges; @property (nonatomic, strong, readonly) NSString *context; +NS_ASSUME_NONNULL_END + @end #endif /* CADataRequest_h */ diff --git a/DigiMeSDK/Core/Classes/Entities/CAFile.h b/DigiMeSDK/Core/Classes/Entities/CAFile.h deleted file mode 100755 index f88173818..000000000 --- a/DigiMeSDK/Core/Classes/Entities/CAFile.h +++ /dev/null @@ -1,55 +0,0 @@ -// -// CAFile.h -// DigiMeSDK -// -// Created on 24/01/2018. -// Copyright © 2018 digi.me Limited. All rights reserved. -// - -#import - -NS_ASSUME_NONNULL_BEGIN - -@interface CAFile : NSObject - -+ (CAFile *)deserialize:(NSData *)data fileId:(NSString *)fileId error:(NSError **)error; - -/** - -init unavailable. Use -initWithFileId: - - @return instancetype - */ -- (instancetype)init NS_UNAVAILABLE; - - -/** - Designated object initializer. - - @param fileId NSString - @return instancetype - */ -- (instancetype)initWithFileId:(NSString *)fileId NS_DESIGNATED_INITIALIZER; - - -/** - Parses content and enriches this object. - - @param content NSArray. - */ -- (void)populateWithContent:(NSArray *)content; - - -/** - File Identifier. This value is returned from the file list. - */ -@property (nonatomic, strong, readonly) NSString *fileId; - - -/** - Serialized representation of the file's json. - */ -@property (nullable, nonatomic, strong, readonly) NSArray *json; - -@end - -NS_ASSUME_NONNULL_END diff --git a/DigiMeSDK/Core/Classes/Entities/CAFile.m b/DigiMeSDK/Core/Classes/Entities/CAFile.m deleted file mode 100755 index 6702e9fcd..000000000 --- a/DigiMeSDK/Core/Classes/Entities/CAFile.m +++ /dev/null @@ -1,55 +0,0 @@ -// -// CAFile.m -// DigiMeSDK -// -// Created on 24/01/2018. -// Copyright © 2018 digi.me Limited. All rights reserved. -// - -#import "CAFile.h" - -@implementation CAFile - -#pragma mark - Deserialization -+ (CAFile *)deserialize:(NSData *)data fileId:(NSString *)fileId error:(NSError * _Nullable __autoreleasing *)error -{ - NSArray *content = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:error]; - - CAFile *file = [[self alloc] initWithFileId:fileId]; - [file populateWithContent:content]; - return file; -} - -#pragma mark - Initialization - --(instancetype)initWithFileId:(NSString *)fileId -{ - self = [super init]; - if (self) - { - _fileId = fileId; - } - - return self; -} - -#pragma mark - Public - -- (void)populateWithContent:(NSArray *)content -{ - _json = content; -} - -#pragma mark - Overrides - --(NSString *)description -{ - NSString *description = [NSString stringWithFormat:@"FileId: %@,\n", self.fileId]; - - description = [NSString stringWithFormat:@"%@%i objects", description, (int)self.json.count]; - - return [NSString stringWithFormat:@"\n<%@: %p,\n%@>", - NSStringFromClass([self class]), self, description]; -} - -@end diff --git a/DigiMeSDK/Core/Classes/Entities/CAFile.swift b/DigiMeSDK/Core/Classes/Entities/CAFile.swift new file mode 100644 index 000000000..00a4040bf --- /dev/null +++ b/DigiMeSDK/Core/Classes/Entities/CAFile.swift @@ -0,0 +1,179 @@ +// +// CAFile.swift +// DigiMeSDK +// +// Created by on 16/05/2019. +// Copyright © 2019 digi.me Limited. All rights reserved. +// + +import Foundation + +public enum CADataParsingError: Error { + case couldNotDeserialiseRawData +} + +public protocol CAInitialisableFromRawData { + init(rawData: Data, mimeType: CAMimeType) throws +} + +@objc +public enum CAMimeType: Int, CaseIterable, ExpressibleByStringLiteral { + public typealias StringLiteralType = String + + public init(stringLiteral value: StringLiteralType) { + switch value { + case "image/jpeg": self = .image_jpeg + case "image/tiff": self = .image_tiff + case "image/png": self = .image_png + case "image/gif": self = .image_gif + case "image/bmp": self = .image_bmp + case "text/plain": self = .text_plain + case "text/json": self = .text_json + case "application/json": self = .application_json + case "application/octet-stream": self = .application_octetStream // Line not strictly required, but present for clarity. + default: self = .application_octetStream + } + } + + case application_json + case application_octetStream + + case image_jpeg + case image_tiff + case image_png + case image_gif + case image_bmp + + case text_plain + case text_json +} + +internal protocol CADataRepresentation: CAInitialisableFromRawData { + + associatedtype FileDataType + + static var compatibleMimeTypes: [CAMimeType] { get } + + var fileMimeType: CAMimeType { get } + var fileContent: FileDataType { get } +} + +internal class CAJSONData: CADataRepresentation { + + public typealias FileDataType = [[AnyHashable: Any]] + public var fileMimeType: CAMimeType + public var fileContent: FileDataType + + public static let compatibleMimeTypes: [CAMimeType] = [CAMimeType.application_json] + + public required init(rawData: Data, mimeType: CAMimeType) throws { + + guard let json = (try? JSONSerialization.jsonObject(with: rawData, options: [])) as? [[AnyHashable: Any]] else { + throw CADataParsingError.couldNotDeserialiseRawData + } + + self.fileContent = json + self.fileMimeType = mimeType + } +} + +internal class CAImageData: CADataRepresentation { + + public typealias FileDataType = UIImage + public var fileMimeType: CAMimeType + public var fileContent: FileDataType + + public static let compatibleMimeTypes: [CAMimeType] = [.image_bmp, .image_gif, .image_png, .image_jpeg, .image_tiff] + + public required init(rawData: Data, mimeType: CAMimeType) throws { + + guard let image = UIImage(data: rawData) else { + throw CADataParsingError.couldNotDeserialiseRawData + } + + self.fileContent = image + self.fileMimeType = mimeType + } +} + +// CARawData doubles as the ObjC compatibility layer, and hence exposes +// a number of 'try and do something' methods. + +@objcMembers +internal class CARawData: NSObject, CADataRepresentation { + + public typealias FileDataType = Data + public var fileMimeType: CAMimeType + public var fileContent: FileDataType + + public static let compatibleMimeTypes: [CAMimeType] = CAMimeType.allCases + + public required init(rawData: Data, mimeType: CAMimeType) throws { + self.fileContent = rawData + self.fileMimeType = mimeType + } +} + +// @available(swift, obsoleted: 0.1, message: "Usage of CAFile is limited to Objective-C. For Swift, which supports generics, use CAFileContainer.") +@objcMembers +public class CAFile: NSObject { + + private var boxedFile: CARawData + public var fileId: String + public var fileMetadata: CAFileMetadata? + + public var fileMimeType: CAMimeType { + return fileMetadata?.mimeType ?? .application_octetStream + } + public var fileContent: Data { + return boxedFile.fileContent + } + + @available(*, deprecated, message: "Please use -[CAFile fileContentAsJSON] instead.") + @available(*, renamed: "fileContentAsJSON") + public var json: [[AnyHashable: Any]]? { + return fileContentAsJSON() + } + + public override var description: String { + let objCount = fileContentAsJSON()?.count ?? -1 + return "File ID: \(fileId), \(objCount >= 0 ? "\(objCount) objects." : "\(fileContent.count) bytes.")" + } + + public init(fileId: String, fileContent: Data, fileMetadata: CAFileMetadata?) { + self.fileId = fileId + self.boxedFile = try! CARawData(rawData: fileContent, mimeType: fileMetadata?.mimeType ?? .application_octetStream) + self.fileMetadata = fileMetadata + } + + public func fileContentAsJSON() -> [[AnyHashable: Any]]? { + return (try? JSONSerialization.jsonObject(with: fileContent, options: [])) as? [[AnyHashable: Any]] + } + + public func fileContentAsImage() -> UIImage? { + return UIImage(data: fileContent) + } + + public func fileContentAsString() -> String? { + return String(data: fileContent, encoding: .utf8) + } +} + +internal class CAFileContainer { + + public var fileId: String + private var file: DataType + public var fileContent: DataType.FileDataType { + return file.fileContent + } + + public init(emptyFileWithId id: String, andDataType dataType: DataType.Type) { + fileId = id + file = try! dataType.init(rawData: Data(), mimeType: CAMimeType.application_octetStream) + } + + public init(fileWithId id: String, rawData: Data, mimeType: CAMimeType, as dataType: DataType.Type) throws { + fileId = id + file = try dataType.init(rawData: rawData, mimeType: mimeType) + } +} diff --git a/DigiMeSDK/Core/Classes/Entities/CAFileMetadata.swift b/DigiMeSDK/Core/Classes/Entities/CAFileMetadata.swift new file mode 100644 index 000000000..b7271491a --- /dev/null +++ b/DigiMeSDK/Core/Classes/Entities/CAFileMetadata.swift @@ -0,0 +1,45 @@ +// +// CAFileMetadata.swift +// DigiMeSDK +// +// Created on 23/05/2019. +// + +import Foundation + +@objcMembers +public class CAFileMetadata: NSObject, Decodable { + + var mimeType: CAMimeType + var reference: String + var tags: [String] + var contractId: String + + enum CodingKeys: String, CodingKey { + case mimeType = "mimetype" + case reference + case tags + case contractId = "contractid" + } + + required public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + self.reference = try container.decode(String.self, forKey: .reference) + self.contractId = try container.decode(String.self, forKey: .contractId) + self.tags = try container.decode([String].self, forKey: .tags) + + let mimeString = try container.decode(String.self, forKey: .mimeType) + self.mimeType = CAMimeType(stringLiteral: mimeString) + } + + @objc(metadataFromJSON:) + public static func metadata(from jsonDict: [AnyHashable: Any]) -> CAFileMetadata? { + do { + let encodedJSON = try JSONSerialization.data(withJSONObject: jsonDict, options: []) + return try JSONDecoder().decode(CAFileMetadata.self, from: encodedJSON) + } + catch { + return nil + } + } +} diff --git a/DigiMeSDK/Core/Classes/Entities/CASession.h b/DigiMeSDK/Core/Classes/Entities/CASession.h index 833aba1e3..0cd1e7f21 100755 --- a/DigiMeSDK/Core/Classes/Entities/CASession.h +++ b/DigiMeSDK/Core/Classes/Entities/CASession.h @@ -8,6 +8,8 @@ #import +NS_ASSUME_NONNULL_BEGIN + extern NSString * const kCARequestSessionKey; extern NSString * const kCADigimeResponse; extern NSString * const kCARequestRegisteredAppID; @@ -35,7 +37,6 @@ extern NSString * const kUserId; extern NSString * const kLibraryId; extern NSString * const kPCloudType; -NS_ASSUME_NONNULL_BEGIN @class CASessionManager; @protocol CADataRequest; diff --git a/DigiMeSDK/Core/Classes/Errors/NSError+SDK.m b/DigiMeSDK/Core/Classes/Errors/NSError+SDK.m index e5f322d0b..01283e9f3 100755 --- a/DigiMeSDK/Core/Classes/Errors/NSError+SDK.m +++ b/DigiMeSDK/Core/Classes/Errors/NSError+SDK.m @@ -55,6 +55,9 @@ + (NSString *)sdkDescription:(SDKError)sdkError case SDKErrorEncryptedDataCallback: return @"Non-nil completion block is not supported when 'decryptsData' is set to NO."; + + case SDKErrorDigiMeAppNotFound: + return @""; } } diff --git a/README.md b/README.md index 36b6cd8df..fe378e4ce 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,17 @@ Download the [latest release](https://github.com/digime/digime-sdk-ios/releases) ## Configuring SDK usage +### Importing the SDK Symbols + +For ease of compatibility with both Objective-C and Swift, the SDK is build as a module. As such, please use module import directives in Objective-C rather than a legacy header import, as these are not supported. For example: + +```objective-c +@import DigiMeSDK; +``` +```swift +import DigiMeSDK +``` + ### Obtaining your Contract ID and App ID Before accessing the public APIs, a valid Contract ID needs to be registered for an App ID. @@ -516,7 +527,7 @@ The following properties can be configured: /** Determines whether additional SDK DEBUG logging is enabled. Defaults to NO. */ -@property (nonatomic) BOOL debugLogEnabled; +@property (nonatomic) BOOL debugLogEnabled; ``` @@ -524,13 +535,19 @@ The following properties can be configured: Each file you fetch from Consent Access is represented by `CAFile` object. -You can access serialized json content (NSArray) of the entire file using the following property on the `CAFile`: +`CAFile` has a `fileContent` property which is the binary data blob of the file. In the vast majority of use cases, the files returned will be serialised JSON which can be deduced from this data blob. -```objective-c -@property (nullable, nonatomic, strong, readonly) NSArray *json; +In some use cases, the data returned may be of another type and not serialisable to JSON. You can inspect the `mimeType` property of `CAFile` to see exactly what type the data is. + +As the most common types of data are JSON and images, we provide two convenience methods for easy deduction: +```objective-c +- (NSArray * _Nullable)fileContentAsJSON; +- (UIImage * _Nullable)fileContentAsImage; ``` +Note that if the data is not compatible, null will be returned. You should check a file's mime type before attempting deduction. If a mime type is not that of an image or JSON, you should manipulate the raw data how you see fit. + For more details about JSON object formats, please see [this guide](http://developers.digi.me/reference-objects) ## Decryption From 1d0d77a1f5bb643cce62dc41a6a92f3be6c27168 Mon Sep 17 00:00:00 2001 From: Jacob King Date: Thu, 30 May 2019 11:53:35 +0100 Subject: [PATCH 2/4] Fixed erroneous baseURL. --- DigiMeSDK/Core/Classes/DMEClientConfiguration.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DigiMeSDK/Core/Classes/DMEClientConfiguration.m b/DigiMeSDK/Core/Classes/DMEClientConfiguration.m index 2a1c97f79..5b0295878 100755 --- a/DigiMeSDK/Core/Classes/DMEClientConfiguration.m +++ b/DigiMeSDK/Core/Classes/DMEClientConfiguration.m @@ -61,11 +61,11 @@ - (NSString *)baseUrl } } - NSString *domain = dict[@"DME_DOMAIN"] ?: @"integration.devdigi.me"; + NSString *domain = dict[@"DME_DOMAIN"] ?: @"digi.me"; _baseUrl = [NSString stringWithFormat:@"https://api.%@/", domain]; } - return @"https://api.integration.devdigi.me/"; + return _baseUrl; } @end From 0d78df2357abc51d80f525719e511daa07eb19c3 Mon Sep 17 00:00:00 2001 From: Jacob King Date: Thu, 30 May 2019 12:03:49 +0100 Subject: [PATCH 3/4] Fixed reference mapping. --- DigiMeSDK/Core/Classes/Entities/CAFileMetadata.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DigiMeSDK/Core/Classes/Entities/CAFileMetadata.swift b/DigiMeSDK/Core/Classes/Entities/CAFileMetadata.swift index b7271491a..d344e7abd 100644 --- a/DigiMeSDK/Core/Classes/Entities/CAFileMetadata.swift +++ b/DigiMeSDK/Core/Classes/Entities/CAFileMetadata.swift @@ -11,7 +11,7 @@ import Foundation public class CAFileMetadata: NSObject, Decodable { var mimeType: CAMimeType - var reference: String + var reference: [String] var tags: [String] var contractId: String @@ -24,7 +24,7 @@ public class CAFileMetadata: NSObject, Decodable { required public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) - self.reference = try container.decode(String.self, forKey: .reference) + self.reference = try container.decode([String].self, forKey: .reference) self.contractId = try container.decode(String.self, forKey: .contractId) self.tags = try container.decode([String].self, forKey: .tags) From 16188ddeb81f921dfba3aa924b8ad960ec140937 Mon Sep 17 00:00:00 2001 From: Jacob King Date: Thu, 30 May 2019 15:06:24 +0100 Subject: [PATCH 4/4] PR requested changes. --- DigiMeSDK/Core/Classes/DMEDataUnpacker.m | 2 +- README.md | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/DigiMeSDK/Core/Classes/DMEDataUnpacker.m b/DigiMeSDK/Core/Classes/DMEDataUnpacker.m index 28327d994..6b0cd2e74 100644 --- a/DigiMeSDK/Core/Classes/DMEDataUnpacker.m +++ b/DigiMeSDK/Core/Classes/DMEDataUnpacker.m @@ -25,7 +25,7 @@ + (nullable NSData *)unpackData:(NSData *)data resolvedMetadata:(CAFileMetadata } NSDictionary *metadataJSON = json[@"fileMetadata"]; - if (metadataJSON) + if (metadataJSON && resolvedMetadata) { *resolvedMetadata = [CAFileMetadata metadataFromJSON:metadataJSON]; } diff --git a/README.md b/README.md index 978f18988..35c6fb319 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ Download the [latest release](https://github.com/digime/digime-sdk-ios/releases) ### Importing the SDK Symbols -For ease of compatibility with both Objective-C and Swift, the SDK is build as a module. As such, please use module import directives in Objective-C rather than a legacy header import, as these are not supported. For example: +For ease of compatibility with both Objective-C and Swift, the SDK is built as a module. As such, please use module import directives in Objective-C rather than a legacy header import, as these are not supported. For example: ```objective-c @import DigiMeSDK; @@ -539,6 +539,27 @@ Each file you fetch from Consent Access is represented by `CAFile` object. In some use cases, the data returned may be of another type and not serialisable to JSON. You can inspect the `mimeType` property of `CAFile` to see exactly what type the data is. +The `CAMimeType` enum represents the various mime types that are currently supported, with those that aren't defaulting to raw bytes (octet stream). + +The supported mime types are detailed below: + +```swift +public enum CAMimeType: Int, CaseIterable, ExpressibleByStringLiteral { + + case application_json + case application_octetStream + + case image_jpeg + case image_tiff + case image_png + case image_gif + case image_bmp + + case text_plain + case text_json +} +``` + As the most common types of data are JSON and images, we provide two convenience methods for easy deduction: ```objective-c