Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 7c2858f

Browse files
committed
another review
1 parent b5a65d0 commit 7c2858f

File tree

3 files changed

+32
-31
lines changed

3 files changed

+32
-31
lines changed

shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm

+7-5
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h"
1212
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate_internal.h"
1313

14-
static NSString* kUIBackgroundMode = @"UIBackgroundModes";
15-
static NSString* kRemoteNotificationCapabitiliy = @"remote-notification";
16-
static NSString* kBackgroundFetchCapatibility = @"fetch";
17-
static NSString* kRestorationStateAppModificationKey = @"mod-date";
14+
static NSString* const kUIBackgroundMode = @"UIBackgroundModes";
15+
static NSString* const kRemoteNotificationCapabitiliy = @"remote-notification";
16+
static NSString* const kBackgroundFetchCapatibility = @"fetch";
17+
static NSString* const kRestorationStateAppModificationKey = @"mod-date";
1818

1919
@interface FlutterAppDelegate ()
2020
@property(nonatomic, copy) FlutterViewController* (^rootFlutterViewControllerGetter)(void);
@@ -334,9 +334,11 @@ - (BOOL)application:(UIApplication*)application
334334

335335
- (int64_t)lastAppModificationTime {
336336
NSDate* fileDate;
337+
NSError* error = nil;
337338
[[[NSBundle mainBundle] executableURL] getResourceValue:&fileDate
338339
forKey:NSURLContentModificationDateKey
339-
error:nil];
340+
error:&error];
341+
NSAssert(error == nil, @"Cannot obtain modification date of main bundle: %@", error);
340342
return [fileDate timeIntervalSince1970];
341343
}
342344

shell/platform/darwin/ios/framework/Source/FlutterRestorationPlugin.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
- (instancetype)initWithChannel:(FlutterMethodChannel*)channel
1616
restorationEnabled:(BOOL)waitForData NS_DESIGNATED_INITIALIZER;
1717

18-
@property(nonatomic, retain) NSData* restorationData;
18+
@property(nonatomic, strong) NSData* restorationData;
1919
- (void)markRestorationComplete;
2020
- (void)reset;
2121
@end

shell/platform/darwin/ios/framework/Source/FlutterRestorationPlugin.mm

+24-25
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111

1212
FLUTTER_ASSERT_NOT_ARC
1313

14+
@interface FlutterRestorationPlugin ()
15+
@property(nonatomic, copy) FlutterResult pendingRequest;
16+
@end
17+
1418
@implementation FlutterRestorationPlugin {
1519
BOOL _waitForData;
1620
BOOL _restorationEnabled;
17-
FlutterResult _pendingRequest;
1821
}
1922

2023
- (instancetype)init {
@@ -40,68 +43,64 @@ - (instancetype)initWithChannel:(FlutterMethodChannel*)channel
4043

4144
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
4245
if ([[call method] isEqualToString:@"put"]) {
46+
NSAssert(self.pendingRequest == nil, @"Cannot put data while a get request is pending.");
4347
FlutterStandardTypedData* data = [call arguments];
44-
_restorationData = [data data];
48+
self.restorationData = [data data];
4549
result(nil);
4650
} else if ([[call method] isEqualToString:@"get"]) {
4751
if (!_restorationEnabled || !_waitForData) {
4852
result([self dataForFramework]);
4953
return;
5054
}
51-
_pendingRequest = [result retain];
55+
NSAssert(self.pendingRequest == nil, @"There can only be one pending request.");
56+
self.pendingRequest = result;
5257
} else {
5358
result(FlutterMethodNotImplemented);
5459
}
5560
}
5661

5762
- (void)setRestorationData:(NSData*)data {
58-
_restorationData = data;
63+
if (data != _restorationData) {
64+
[_restorationData release];
65+
_restorationData = [data retain];
66+
}
5967
_waitForData = NO;
60-
if (_pendingRequest != nil) {
61-
_pendingRequest([self dataForFramework]);
62-
[_pendingRequest release];
63-
_pendingRequest = nil;
68+
if (self.pendingRequest != nil) {
69+
self.pendingRequest([self dataForFramework]);
70+
self.pendingRequest = nil;
6471
}
6572
}
6673

6774
- (void)markRestorationComplete {
6875
_waitForData = NO;
69-
if (_pendingRequest != nil) {
76+
if (self.pendingRequest != nil) {
7077
NSAssert(_restorationEnabled, @"No request can be pending when restoration is disabled.");
71-
_pendingRequest([self dataForFramework]);
72-
[_pendingRequest release];
73-
_pendingRequest = nil;
78+
self.pendingRequest([self dataForFramework]);
79+
self.pendingRequest = nil;
7480
}
7581
}
7682

7783
- (void)reset {
78-
_restorationData = nil;
79-
if (_pendingRequest != nil) {
80-
[_pendingRequest release];
81-
}
82-
_pendingRequest = nil;
84+
self.pendingRequest = nil;
85+
self.restorationData = nil;
8386
}
8487

8588
- (NSDictionary*)dataForFramework {
8689
if (!_restorationEnabled) {
8790
return @{@"enabled" : @NO};
8891
}
89-
if (_restorationData == nil) {
92+
if (self.restorationData == nil) {
9093
return @{@"enabled" : @YES};
9194
}
9295
return @{
9396
@"enabled" : @YES,
94-
@"data" : [FlutterStandardTypedData typedDataWithBytes:_restorationData]
97+
@"data" : [FlutterStandardTypedData typedDataWithBytes:self.restorationData]
9598
};
9699
}
97100

98101
- (void)dealloc {
99-
if (_restorationData != nil) {
100-
[_restorationData release];
101-
}
102-
if (_pendingRequest != nil) {
103-
[_pendingRequest release];
104-
}
102+
[_restorationData release];
103+
[_pendingRequest release];
105104
[super dealloc];
106105
}
107106

0 commit comments

Comments
 (0)