David PHAM-VAN

Fix iOS printing issues

  1 +# 1.3.2
  2 +* Fix iOS printing issues
  3 +
1 # 1.3.1 4 # 1.3.1
2 * Fix pana linting notices 5 * Fix pana linting notices
3 6
@@ -63,6 +63,7 @@ @@ -63,6 +63,7 @@
63 **/ios/ServiceDefinitions.json 63 **/ios/ServiceDefinitions.json
64 **/ios/Runner/GeneratedPluginRegistrant.* 64 **/ios/Runner/GeneratedPluginRegistrant.*
65 **/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings 65 **/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings
  66 +**/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
66 **/ios/Podfile.lock 67 **/ios/Podfile.lock
67 **/ios/Podfile 68 **/ios/Podfile
68 69
@@ -14,7 +14,6 @@ @@ -14,7 +14,6 @@
14 669503AD9820A2FB8EB7D135 /* libPods-Runner.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 438EF44EBD2180BA9FEB6DD7 /* libPods-Runner.a */; }; 14 669503AD9820A2FB8EB7D135 /* libPods-Runner.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 438EF44EBD2180BA9FEB6DD7 /* libPods-Runner.a */; };
15 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; }; 15 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; };
16 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 16 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
17 - 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB21CF90195004384FC /* Debug.xcconfig */; };  
18 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; }; 17 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; };
19 97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; }; 18 97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; };
20 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 19 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
@@ -173,7 +172,7 @@ @@ -173,7 +172,7 @@
173 97C146E61CF9000F007C117D /* Project object */ = { 172 97C146E61CF9000F007C117D /* Project object */ = {
174 isa = PBXProject; 173 isa = PBXProject;
175 attributes = { 174 attributes = {
176 - LastUpgradeCheck = 0910; 175 + LastUpgradeCheck = 1010;
177 ORGANIZATIONNAME = "The Chromium Authors"; 176 ORGANIZATIONNAME = "The Chromium Authors";
178 TargetAttributes = { 177 TargetAttributes = {
179 97C146ED1CF9000F007C117D = { 178 97C146ED1CF9000F007C117D = {
@@ -206,7 +205,6 @@ @@ -206,7 +205,6 @@
206 files = ( 205 files = (
207 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */, 206 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */,
208 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, 207 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */,
209 - 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */,  
210 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, 208 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */,
211 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, 209 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */,
212 ); 210 );
@@ -336,12 +334,14 @@ @@ -336,12 +334,14 @@
336 CLANG_WARN_BOOL_CONVERSION = YES; 334 CLANG_WARN_BOOL_CONVERSION = YES;
337 CLANG_WARN_COMMA = YES; 335 CLANG_WARN_COMMA = YES;
338 CLANG_WARN_CONSTANT_CONVERSION = YES; 336 CLANG_WARN_CONSTANT_CONVERSION = YES;
  337 + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
339 CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 338 CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
340 CLANG_WARN_EMPTY_BODY = YES; 339 CLANG_WARN_EMPTY_BODY = YES;
341 CLANG_WARN_ENUM_CONVERSION = YES; 340 CLANG_WARN_ENUM_CONVERSION = YES;
342 CLANG_WARN_INFINITE_RECURSION = YES; 341 CLANG_WARN_INFINITE_RECURSION = YES;
343 CLANG_WARN_INT_CONVERSION = YES; 342 CLANG_WARN_INT_CONVERSION = YES;
344 CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 343 CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
  344 + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
345 CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 345 CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
346 CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 346 CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
347 CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 347 CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
@@ -408,12 +408,14 @@ @@ -408,12 +408,14 @@
408 CLANG_WARN_BOOL_CONVERSION = YES; 408 CLANG_WARN_BOOL_CONVERSION = YES;
409 CLANG_WARN_COMMA = YES; 409 CLANG_WARN_COMMA = YES;
410 CLANG_WARN_CONSTANT_CONVERSION = YES; 410 CLANG_WARN_CONSTANT_CONVERSION = YES;
  411 + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
411 CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 412 CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
412 CLANG_WARN_EMPTY_BODY = YES; 413 CLANG_WARN_EMPTY_BODY = YES;
413 CLANG_WARN_ENUM_CONVERSION = YES; 414 CLANG_WARN_ENUM_CONVERSION = YES;
414 CLANG_WARN_INFINITE_RECURSION = YES; 415 CLANG_WARN_INFINITE_RECURSION = YES;
415 CLANG_WARN_INT_CONVERSION = YES; 416 CLANG_WARN_INT_CONVERSION = YES;
416 CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 417 CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
  418 + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
417 CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 419 CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
418 CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 420 CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
419 CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 421 CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
@@ -462,12 +464,14 @@ @@ -462,12 +464,14 @@
462 CLANG_WARN_BOOL_CONVERSION = YES; 464 CLANG_WARN_BOOL_CONVERSION = YES;
463 CLANG_WARN_COMMA = YES; 465 CLANG_WARN_COMMA = YES;
464 CLANG_WARN_CONSTANT_CONVERSION = YES; 466 CLANG_WARN_CONSTANT_CONVERSION = YES;
  467 + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
465 CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 468 CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
466 CLANG_WARN_EMPTY_BODY = YES; 469 CLANG_WARN_EMPTY_BODY = YES;
467 CLANG_WARN_ENUM_CONVERSION = YES; 470 CLANG_WARN_ENUM_CONVERSION = YES;
468 CLANG_WARN_INFINITE_RECURSION = YES; 471 CLANG_WARN_INFINITE_RECURSION = YES;
469 CLANG_WARN_INT_CONVERSION = YES; 472 CLANG_WARN_INT_CONVERSION = YES;
470 CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 473 CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
  474 + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
471 CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 475 CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
472 CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 476 CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
473 CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 477 CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
1 <?xml version="1.0" encoding="UTF-8"?> 1 <?xml version="1.0" encoding="UTF-8"?>
2 <Scheme 2 <Scheme
3 - LastUpgradeVersion = "0910" 3 + LastUpgradeVersion = "1010"
4 version = "1.3"> 4 version = "1.3">
5 <BuildAction 5 <BuildAction
6 parallelizeBuildables = "YES" 6 parallelizeBuildables = "YES"
@@ -26,7 +26,6 @@ @@ -26,7 +26,6 @@
26 buildConfiguration = "Debug" 26 buildConfiguration = "Debug"
27 selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" 27 selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28 selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" 28 selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29 - language = ""  
30 shouldUseLaunchSchemeArgsEnv = "YES"> 29 shouldUseLaunchSchemeArgsEnv = "YES">
31 <Testables> 30 <Testables>
32 </Testables> 31 </Testables>
@@ -46,7 +45,6 @@ @@ -46,7 +45,6 @@
46 buildConfiguration = "Debug" 45 buildConfiguration = "Debug"
47 selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" 46 selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
48 selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" 47 selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
49 - language = ""  
50 launchStyle = "0" 48 launchStyle = "0"
51 useCustomWorkingDirectory = "NO" 49 useCustomWorkingDirectory = "NO"
52 ignoresPersistentStateOnLaunch = "NO" 50 ignoresPersistentStateOnLaunch = "NO"
@@ -20,8 +20,7 @@ @@ -20,8 +20,7 @@
20 20
21 - (instancetype)init:(FlutterMethodChannel*)channel; 21 - (instancetype)init:(FlutterMethodChannel*)channel;
22 - (void)drawPageAtIndex:(NSInteger)pageIndex inRect:(CGRect)printableRect; 22 - (void)drawPageAtIndex:(NSInteger)pageIndex inRect:(CGRect)printableRect;
  23 +- (void)setDocument:(NSData*)data;
23 24
24 @property(nonatomic, readonly) NSInteger numberOfPages; 25 @property(nonatomic, readonly) NSInteger numberOfPages;
25 -@property(nonatomic, readonly) NSLock* lock;  
26 -@property(nonatomic) CGPDFDocumentRef pdfDocument;  
27 @end 26 @end
@@ -18,11 +18,10 @@ @@ -18,11 +18,10 @@
18 18
19 @implementation PdfPrintPageRenderer { 19 @implementation PdfPrintPageRenderer {
20 FlutterMethodChannel* channel; 20 FlutterMethodChannel* channel;
  21 + CGPDFDocumentRef pdfDocument;
  22 + NSLock* lock;
21 } 23 }
22 24
23 -@synthesize lock;  
24 -@synthesize pdfDocument;  
25 -  
26 - (instancetype)init:(FlutterMethodChannel*)channel { 25 - (instancetype)init:(FlutterMethodChannel*)channel {
27 self = [super init]; 26 self = [super init];
28 self->channel = channel; 27 self->channel = channel;
@@ -31,6 +30,12 @@ @@ -31,6 +30,12 @@
31 return self; 30 return self;
32 } 31 }
33 32
  33 +- (void)dealloc {
  34 + if (self->pdfDocument != nil) {
  35 + CGPDFDocumentRelease(self->pdfDocument);
  36 + }
  37 +}
  38 +
34 - (NSInteger)numberOfPages { 39 - (NSInteger)numberOfPages {
35 NSNumber* width = [[NSNumber alloc] initWithDouble:self.paperRect.size.width]; 40 NSNumber* width = [[NSNumber alloc] initWithDouble:self.paperRect.size.width];
36 NSNumber* height = 41 NSNumber* height =
@@ -75,4 +80,24 @@ @@ -75,4 +80,24 @@
75 CGContextDrawPDFPage(ctx, page); 80 CGContextDrawPDFPage(ctx, page);
76 } 81 }
77 82
  83 +void dataProviderReleaseDataCallback(void* info,
  84 + const void* data,
  85 + size_t size) {
  86 + free((void*)data);
  87 +}
  88 +
  89 +- (void)setDocument:(NSData*)data {
  90 + void* buffer = malloc(data.length);
  91 + memcpy(buffer, data.bytes, data.length);
  92 + CGDataProviderRef dataProvider = CGDataProviderCreateWithData(
  93 + NULL, buffer, data.length, dataProviderReleaseDataCallback);
  94 + if (pdfDocument != nil) {
  95 + CGPDFDocumentRelease(pdfDocument);
  96 + pdfDocument = nil;
  97 + }
  98 + pdfDocument = CGPDFDocumentCreateWithProvider(dataProvider);
  99 + CGDataProviderRelease(dataProvider);
  100 + [lock unlock];
  101 +}
  102 +
78 @end 103 @end
@@ -33,7 +33,7 @@ @@ -33,7 +33,7 @@
33 - (instancetype)init:(FlutterMethodChannel*)channel { 33 - (instancetype)init:(FlutterMethodChannel*)channel {
34 self = [super init]; 34 self = [super init];
35 self->channel = channel; 35 self->channel = channel;
36 - self->renderer = [[PdfPrintPageRenderer alloc] init:channel]; 36 + self->renderer = nil;
37 return self; 37 return self;
38 } 38 }
39 39
@@ -72,6 +72,7 @@ @@ -72,6 +72,7 @@
72 printInfo.jobName = name; 72 printInfo.jobName = name;
73 printInfo.outputType = UIPrintInfoOutputGeneral; 73 printInfo.outputType = UIPrintInfoOutputGeneral;
74 controller.printInfo = printInfo; 74 controller.printInfo = printInfo;
  75 + renderer = [[PdfPrintPageRenderer alloc] init:channel];
75 [controller setPrintPageRenderer:renderer]; 76 [controller setPrintPageRenderer:renderer];
76 UIPrintInteractionCompletionHandler completionHandler = 77 UIPrintInteractionCompletionHandler completionHandler =
77 ^(UIPrintInteractionController* printController, BOOL completed, 78 ^(UIPrintInteractionController* printController, BOOL completed,
@@ -80,25 +81,14 @@ @@ -80,25 +81,14 @@
80 NSLog(@"FAILED! due to error in domain %@ with error code %u", 81 NSLog(@"FAILED! due to error in domain %@ with error code %u",
81 error.domain, (unsigned int)error.code); 82 error.domain, (unsigned int)error.code);
82 } 83 }
83 - if (self->renderer.pdfDocument != nil) {  
84 - CGPDFDocumentRelease(self->renderer.pdfDocument);  
85 - self->renderer.pdfDocument = nil;  
86 - } 84 + self->renderer = nil;
87 }; 85 };
88 86
89 [controller presentAnimated:YES completionHandler:completionHandler]; 87 [controller presentAnimated:YES completionHandler:completionHandler];
90 } 88 }
91 89
92 - (void)writePdf:(nonnull FlutterStandardTypedData*)data { 90 - (void)writePdf:(nonnull FlutterStandardTypedData*)data {
93 - CGDataProviderRef dataProvider = CGDataProviderCreateWithData(  
94 - NULL, data.data.bytes, data.data.length, NULL);  
95 - if (renderer.pdfDocument != nil) {  
96 - CGPDFDocumentRelease(renderer.pdfDocument);  
97 - renderer.pdfDocument = nil;  
98 - }  
99 - renderer.pdfDocument = CGPDFDocumentCreateWithProvider(dataProvider);  
100 - CGDataProviderRelease(dataProvider);  
101 - [renderer.lock unlock]; 91 + [renderer setDocument:data.data];
102 } 92 }
103 93
104 - (void)sharePdf:(nonnull FlutterStandardTypedData*)data 94 - (void)sharePdf:(nonnull FlutterStandardTypedData*)data
@@ -2,7 +2,7 @@ name: printing @@ -2,7 +2,7 @@ name: printing
2 author: David PHAM-VAN <dev.nfet.net@gmail.com> 2 author: David PHAM-VAN <dev.nfet.net@gmail.com>
3 description: Plugin that allows Flutter apps to generate and print documents to android or ios compatible printers 3 description: Plugin that allows Flutter apps to generate and print documents to android or ios compatible printers
4 homepage: https://github.com/DavBfr/dart_pdf/tree/master/printing 4 homepage: https://github.com/DavBfr/dart_pdf/tree/master/printing
5 -version: 1.3.1 5 +version: 1.3.2
6 6
7 environment: 7 environment:
8 sdk: ">=1.19.0 <3.0.0" 8 sdk: ">=1.19.0 <3.0.0"