Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
flutter_boost_1.22.4
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李增强
flutter_boost_1.22.4
Commits
5173dd21
Commit
5173dd21
authored
5 years ago
by
Jidong Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
78c23ac1
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
611 additions
and
22 deletions
+611
-22
ios/Classes/1.0/FLBFactory.m
ios/Classes/1.0/FLBFactory.m
+1
-0
ios/Classes/1.0/FLBFlutterEngineOld.m
ios/Classes/1.0/FLBFlutterEngineOld.m
+0
-4
ios/Classes/1.0/FLBFlutterProvider.h
ios/Classes/1.0/FLBFlutterProvider.h
+1
-3
ios/Classes/1.0/FLBViewProviderFactory.m
ios/Classes/1.0/FLBViewProviderFactory.m
+0
-8
ios/Classes/1.0/Support/Cache/FLBStackCache.h
ios/Classes/1.0/Support/Cache/FLBStackCache.h
+72
-0
ios/Classes/1.0/Support/Cache/FLBStackCache.m
ios/Classes/1.0/Support/Cache/FLBStackCache.m
+210
-0
ios/Classes/1.0/Support/Cache/FLBStackCacheObjectImg.h
ios/Classes/1.0/Support/Cache/FLBStackCacheObjectImg.h
+7
-7
ios/Classes/1.0/Support/Cache/FLBStackCacheObjectImg.m
ios/Classes/1.0/Support/Cache/FLBStackCacheObjectImg.m
+116
-0
ios/Classes/1.0/Support/Memory/FLBMemoryInspector.h
ios/Classes/1.0/Support/Memory/FLBMemoryInspector.h
+47
-0
ios/Classes/1.0/Support/Memory/FLBMemoryInspector.mm
ios/Classes/1.0/Support/Memory/FLBMemoryInspector.mm
+157
-0
No files found.
ios/Classes/1.0/FLBFactory.m
View file @
5173dd21
...
...
@@ -38,4 +38,5 @@
return
FLBFlutterViewContainer
.
new
;
}
@end
This diff is collapsed.
Click to expand it.
ios/Classes/1.0/FLBFlutterEngineOld.m
View file @
5173dd21
...
...
@@ -100,9 +100,5 @@
[
self
.
viewController
sendOnChannel
:
channel
message
:
data
];
}
-
(
void
)
setAccessibilityEnable
:(
BOOL
)
enable
{
self
.
viewController
.
accessibilityEnable
=
enable
;
}
@end
This diff is collapsed.
Click to expand it.
ios/Classes/1.0/FLBFlutterProvider.h
View file @
5173dd21
...
...
@@ -34,9 +34,7 @@ NS_ASSUME_NONNULL_BEGIN
@protocol
FLBFlutterProvider
<
NSObject
>
@required
-
(
FlutterEngine
*
)
engine
;
-
(
void
)
atacheToViewController
:(
FlutterViewController
*
)
vc
;
-
(
void
)
detach
;
-
(
void
)
pause
;
-
(
void
)
resume
;
-
(
void
)
inactive
;
...
...
This diff is collapsed.
Click to expand it.
ios/Classes/1.0/FLBViewProviderFactory.m
View file @
5173dd21
...
...
@@ -32,20 +32,12 @@
-
(
id
<
FLBFlutterViewProvider
>
)
createViewProviderWithPlatform
:(
id
<
FLBPlatform
>
)
platform
{
#if RELEASE_1_0
return
[
FLBFlutterEngine
new
];
#else
return
[[
FLBFlutterEngineOld
alloc
]
initWithPlatform
:
platform
];
#endif
}
-
(
id
<
FLBFlutterViewProvider
>
)
createViewProvider
{
#if RELEASE_1_0
return
[
FLBFlutterEngine
new
];
#else
return
[
FLBFlutterEngineOld
new
];
#endif
}
@end
This diff is collapsed.
Click to expand it.
ios/Classes/1.0/
FLBFlutterEngine.m
→
ios/Classes/1.0/
Support/Cache/FLBStackCache.h
View file @
5173dd21
...
...
@@ -22,72 +22,51 @@
* THE SOFTWARE.
*/
#import "FLBFlutterEngine.h"
#import <Flutter/Flutter.h>
#import "FLBFlutterViewControllerAdaptor.h"
#import <Foundation/Foundation.h>
#if RELEASE_1_0
@class
FLBStackCache
;
@interface
FLBFlutterEngine
()
@property
(
nonatomic
,
strong
)
FLBFlutterViewControllerAdaptor
*
viewController
;
@property
(
nonatomic
,
strong
)
FlutterEngine
*
engine
;
@end
@implementation
FLBFlutterEngine
@protocol
FLBStackCacheObject
<
NSObject
>
-
(
instancetype
)
init
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
if
(
self
=
[
super
init
])
{
_engine
=
[[
FlutterEngine
alloc
]
initWithName
:
@"io.flutter"
project
:
nil
];
[
_engine
runWithEntrypoint
:
nil
];
_viewController
=
[[
FLBFlutterViewControllerAdaptor
alloc
]
initWithEngine
:
_engine
nibName:
nil
bundle:
nil
];
[
_viewController
view
];
Class
clazz
=
NSClassFromString
(
@"GeneratedPluginRegistrant"
);
if
(
clazz
)
{
if
([
clazz
respondsToSelector
:
NSSelectorFromString
(
@"registerWithRegistry:"
)])
{
[
clazz
performSelector
:
NSSelectorFromString
(
@"registerWithRegistry:"
)
withObject:
_viewController
];
}
}
}
return
self
;
#pragma clang diagnostic pop
}
@required
@property
(
nonatomic
,
copy
)
NSString
*
key
;
-
(
FlutterViewController
*
)
viewController
{
return
_viewController
;
}
-
(
BOOL
)
writeToFileWithKey
:(
NSString
*
)
key
queue
:(
dispatch_queue_t
)
queue
cache
:(
FLBStackCache
*
)
cache
completion
:(
void
(
^
)(
NSError
*
err
,
NSString
*
path
))
completion
;
-
(
void
)
pause
{
//TODO: [[_engine.get() lifecycleChannel] sendMessage:@"AppLifecycleState.paused"];
[
self
.
viewController
boost_viewWillDisappear
:
NO
];
[
self
.
viewController
boost_viewDidDisappear
:
NO
];
}
+
(
BOOL
)
loadFromFileWithKey
:(
NSString
*
)
key
queue
:(
dispatch_queue_t
)
queue
cache
:(
FLBStackCache
*
)
cache
completion
:(
void
(
^
)(
NSError
*
err
,
id
<
FLBStackCacheObject
>
))
completion
;
-
(
void
)
resume
{
//TODO: [[_engine.get() lifecycleChannel] sendMessage:@"AppLifecycleState.resumed"];
[
self
.
viewController
boost_viewWillAppear
:
NO
];
[
self
.
viewController
boost_viewDidAppear
:
NO
];
}
-
(
BOOL
)
removeCachedFileWithKey
:(
NSString
*
)
key
queue
:(
dispatch_queue_t
)
queue
cache
:(
FLBStackCache
*
)
cache
completion
:(
void
(
^
)(
NSError
*
,
NSString
*
))
completion
;
-
(
void
)
inactive
{
[[
_engine
lifecycleChannel
]
sendMessage
:
@"AppLifecycleState.inactive"
];
}
-
(
void
)
setAccessibilityEnable
:(
BOOL
)
enable
{
self
.
viewController
.
accessibilityEnable
=
enable
;
}
@end
#endif
@interface
FLBStackCache
:
NSObject
+
(
instancetype
)
sharedInstance
;
/**
* Num of objects allowed in memory.
* Default value is set to 2.
*/
@property
(
nonatomic
,
assign
)
NSUInteger
inMemoryCount
;
#pragma mark - basic operations.
-
(
void
)
pushObject
:(
id
<
FLBStackCacheObject
>
)
obj
key
:(
NSString
*
)
key
;
-
(
id
<
FLBStackCacheObject
>
)
remove
:(
NSString
*
)
key
;
-
(
void
)
invalidate
:(
NSString
*
)
key
;
-
(
BOOL
)
empty
;
-
(
void
)
clear
;
-
(
id
<
FLBStackCacheObject
>
)
objectForKey
:(
NSString
*
)
key
;
#pragma mark - Disk thing.
-
(
NSString
*
)
cacheDir
;
@end
This diff is collapsed.
Click to expand it.
ios/Classes/1.0/Support/Cache/FLBStackCache.m
0 → 100755
View file @
5173dd21
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#import "FLBStackCache.h"
@interface
FLBStackCache
()
@property
(
nonatomic
,
strong
)
NSMutableArray
*
keyStack
;
@property
(
nonatomic
,
strong
)
NSMutableDictionary
*
typesMap
;
@property
(
nonatomic
,
strong
)
NSMutableDictionary
*
inMemoryObjectsMap
;
@property
(
nonatomic
,
strong
)
NSMutableDictionary
*
loadinMap
;
@property
(
nonatomic
,
strong
)
dispatch_queue_t
queueIO
;
@end
@implementation
FLBStackCache
+
(
instancetype
)
sharedInstance
{
static
id
sInstance
=
nil
;
static
dispatch_once_t
onceToken
;
dispatch_once
(
&
onceToken
,
^
{
sInstance
=
[
self
.
class
new
];
});
return
sInstance
;
}
-
(
BOOL
)
empty
{
return
_keyStack
.
count
<=
0
;
}
-
(
void
)
clear
{
[
self
.
keyStack
removeAllObjects
];
[
self
.
inMemoryObjectsMap
removeAllObjects
];
[
self
.
typesMap
removeAllObjects
];
NSError
*
err
=
nil
;
[[
NSFileManager
defaultManager
]
removeItemAtPath
:
self
.
cacheDir
error
:
&
err
];
if
(
err
)
{
NSLog
(
@"fail to remove cache dir %@"
,
err
);
}
}
-
(
instancetype
)
init
{
if
(
self
=
[
super
init
])
{
_keyStack
=
[
NSMutableArray
new
];
_inMemoryObjectsMap
=
[
NSMutableDictionary
new
];
_loadinMap
=
[
NSMutableDictionary
new
];
_typesMap
=
[
NSMutableDictionary
new
];
_queueIO
=
dispatch_queue_create
(
"Stack cache working queue"
,
NULL
);
}
_inMemoryCount
=
2
;
return
self
;
}
-
(
void
)
pushObject
:(
id
<
FLBStackCacheObject
>
)
obj
key
:(
NSString
*
)
key
{
if
(
!
obj
||
key
.
length
<=
0
)
{
return
;
}
if
(
!
[
_keyStack
containsObject
:
key
]){
[
_keyStack
addObject
:
key
];
}
else
{
//return;
}
obj
.
key
=
key
;
_typesMap
[
key
]
=
obj
.
class
;
_inMemoryObjectsMap
[
key
]
=
obj
;
for
(
NSUInteger
i
=
_keyStack
.
count
-
_inMemoryObjectsMap
.
count
;
i
<
_keyStack
.
count
&&
_inMemoryObjectsMap
.
count
>
_inMemoryCount
;
i
++
){
NSString
*
keyToSave
=
_keyStack
[
i
];
if
(
_inMemoryObjectsMap
[
keyToSave
]){
id
<
FLBStackCacheObject
>
ob
=
_inMemoryObjectsMap
[
keyToSave
];
[
_inMemoryObjectsMap
removeObjectForKey
:
keyToSave
];
[
ob
writeToFileWithKey
:
keyToSave
queue:
_queueIO
cache:
self
completion:
^
(
NSError
*
err
,
NSString
*
path
)
{
if
(
err
)
{
NSLog
(
@"Caching object to file failed!"
);
}
}];
}
}
}
-
(
id
<
FLBStackCacheObject
>
)
objectForKey
:(
NSString
*
)
key
{
return
_inMemoryObjectsMap
[
key
];
}
-
(
id
<
FLBStackCacheObject
>
)
remove
:(
NSString
*
)
key
{
if
([
self
empty
])
return
nil
;
if
(
!
[
_keyStack
containsObject
:
key
])
return
nil
;
id
ob
=
_inMemoryObjectsMap
[
key
];
[
_keyStack
removeObject
:
key
];
[
_inMemoryObjectsMap
removeObjectForKey
:
key
];
[
_typesMap
removeObjectForKey
:
key
];
[
self
preloadIfNeeded
];
return
ob
;
}
-
(
void
)
invalidate
:(
NSString
*
)
key
{
if
(
!
key
||
[
self
empty
])
return
;
if
(
!
[
_keyStack
containsObject
:
key
])
return
;
id
<
FLBStackCacheObject
>
ob
=
_inMemoryObjectsMap
[
key
];
[
ob
removeCachedFileWithKey
:
key
queue:
_queueIO
cache:
self
completion:
^
(
NSError
*
err
,
NSString
*
k
)
{
}];
[
_inMemoryObjectsMap
removeObjectForKey
:
key
];
[
self
preloadIfNeeded
];
}
-
(
void
)
preloadIfNeeded
{
for
(
NSString
*
key
in
self
.
keyStack
.
reverseObjectEnumerator
){
Class
typeClass
=
_typesMap
[
key
];
id
cache
=
_inMemoryObjectsMap
[
key
];
if
(
typeClass
&&
!
cache
&&
[
typeClass
conformsToProtocol
:
@protocol
(
FLBStackCacheObject
)]){
_loadinMap
[
key
]
=
@
(
YES
);
[
typeClass
loadFromFileWithKey
:
key
queue:
_queueIO
cache:
self
completion:
^
(
NSError
*
err
,
id
<
FLBStackCacheObject
>
ob
){
[
self
.
loadinMap
removeObjectForKey
:
key
];
if
(
ob
&&
!
err
)
{
if
(
self
.
typesMap
[
key
]){
self
.
inMemoryObjectsMap
[
key
]
=
ob
;
}
}
else
{
NSLog
(
@"preload object from file failed!"
);
}
}];
}
if
(
_inMemoryObjectsMap
.
count
+
_loadinMap
.
count
>=
_inMemoryCount
){
break
;
}
}
}
-
(
NSString
*
)
cacheDir
{
static
NSString
*
cachePath
=
nil
;
if
(
!
cachePath
)
{
NSArray
*
paths
=
NSSearchPathForDirectoriesInDomains
(
NSCachesDirectory
,
NSUserDomainMask
,
YES
);
NSString
*
cacheDirectory
=
[
paths
objectAtIndex
:
0
];
cachePath
=
[
cacheDirectory
stringByAppendingPathComponent
:
@"FlutterScreenshots"
];
}
BOOL
dir
=
NO
;
if
(
!
[[
NSFileManager
defaultManager
]
fileExistsAtPath
:
cachePath
isDirectory
:
&
dir
]){
NSError
*
eror
=
nil
;
[[
NSFileManager
defaultManager
]
createDirectoryAtPath
:
cachePath
withIntermediateDirectories:
YES
attributes:
nil
error:
&
eror
];
if
(
eror
)
{
NSLog
(
@"%@"
,
eror
);
}
}
return
cachePath
;
}
@end
This diff is collapsed.
Click to expand it.
ios/Classes/1.0/
FLBFlutterEngine
.h
→
ios/Classes/1.0/
Support/Cache/FLBStackCacheObjectImg
.h
View file @
5173dd21
...
...
@@ -23,15 +23,15 @@
*/
#import <Foundation/Foundation.h>
#import "FLBFlutterViewProvider.h"
NS_ASSUME_NONNULL_BEGIN
#import "FLBStackCache.h"
#if RELEASE_1_0
@interface
FLBStackCacheObjectImg
:
NSObject
<
FLBStackCacheObject
>
@interface
FLBFlutterEngine
:
NSObject
<
FLBFlutterViewProvider
>
@end
@property
(
nonatomic
,
copy
)
NSString
*
key
;
-
(
instancetype
)
initWithImage
:(
UIImage
*
)
image
;
#endif
-
(
UIImage
*
)
image
;
NS_ASSUME_NONNULL_END
@end
This diff is collapsed.
Click to expand it.
ios/Classes/1.0/Support/Cache/FLBStackCacheObjectImg.m
0 → 100755
View file @
5173dd21
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#import "FLBStackCacheObjectImg.h"
@interface
FLBStackCacheObjectImg
()
@property
(
nonatomic
,
strong
)
UIImage
*
image
;
@end
@implementation
FLBStackCacheObjectImg
-
(
instancetype
)
initWithImage
:(
UIImage
*
)
image
{
if
(
self
=
[
super
init
])
{
_image
=
image
;
}
return
self
;
}
+
(
BOOL
)
loadFromFileWithKey
:(
NSString
*
)
key
queue
:(
dispatch_queue_t
)
queue
cache
:(
FLBStackCache
*
)
cache
completion
:(
void
(
^
)(
NSError
*
,
id
<
FLBStackCacheObject
>
))
completion
{
dispatch_async
(
queue
,
^
{
UIImage
*
image
=
[[
UIImage
alloc
]
initWithContentsOfFile
:[
self
filePathByKey
:
key
dirPath
:
cache
.
cacheDir
]];
if
(
completion
)
{
if
(
image
)
{
FLBStackCacheObjectImg
*
ob
=
[[
FLBStackCacheObjectImg
alloc
]
initWithImage
:
image
];
ob
.
key
=
key
;
completion
(
nil
,
ob
);
}
else
{
completion
([
NSError
new
],
nil
);
}
}
});
return
YES
;
}
+
(
NSString
*
)
filePathByKey
:(
NSString
*
)
key
dirPath
:(
NSString
*
)
cacheDir
{
key
=
[
key
stringByReplacingOccurrencesOfString
:
@"/"
withString
:
@""
];
key
=
[
key
stringByReplacingOccurrencesOfString
:
@":"
withString
:
@""
];
NSString
*
path
=
[
cacheDir
stringByAppendingPathComponent
:
key
];
return
path
;
}
-
(
BOOL
)
writeToFileWithKey
:(
NSString
*
)
key
queue
:(
dispatch_queue_t
)
queue
cache
:(
FLBStackCache
*
)
cache
completion
:(
void
(
^
)(
NSError
*
,
NSString
*
))
completion
{
if
(
!
_image
){
return
NO
;
}
dispatch_async
(
queue
,
^
{
NSData
*
imgData
=
UIImagePNGRepresentation
(
self
.
image
);
NSString
*
filePath
=
[
FLBStackCacheObjectImg
filePathByKey
:
key
dirPath
:
cache
.
cacheDir
];
[
imgData
writeToFile
:
filePath
atomically
:
YES
];
if
(
completion
)
{
completion
(
nil
,
key
);
}
});
return
YES
;
}
-
(
BOOL
)
removeCachedFileWithKey
:(
NSString
*
)
key
queue
:(
dispatch_queue_t
)
queue
cache
:(
FLBStackCache
*
)
cache
completion
:(
void
(
^
)(
NSError
*
,
NSString
*
))
completion
{
if
(
!
key
){
return
NO
;
}
dispatch_async
(
queue
,
^
{
NSString
*
filePath
=
[
FLBStackCacheObjectImg
filePathByKey
:
key
dirPath
:
cache
.
cacheDir
];
NSError
*
err
=
nil
;
[
NSFileManager
.
defaultManager
removeItemAtPath
:
filePath
error
:
&
err
];
if
(
completion
)
{
completion
(
err
,
key
);
}
});
return
YES
;
}
@end
This diff is collapsed.
Click to expand it.
ios/Classes/1.0/Support/Memory/FLBMemoryInspector.h
0 → 100755
View file @
5173dd21
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#import <Foundation/Foundation.h>
#define kFLBMemoryInspectorChangedNotification @"__FlutterMemoryInspectorChangedNotification__"
#define kFLBMemoryInspectorKeyCondition @"condition"
typedef
NS_ENUM
(
NSUInteger
,
FLBMemoryCondition
)
{
FLBMemoryConditionUnknown
,
FLBMemoryConditionNormal
,
FLBMemoryConditionLowMemory
,
FLBMemoryConditionExtremelyLow
,
FLBMemoryConditionAboutToDie
};
@interface
FLBMemoryInspector
:
NSObject
+
(
instancetype
)
sharedInstance
;
-
(
FLBMemoryCondition
)
currentCondition
;
-
(
int64_t
)
currentFootPrint
;
-
(
int64_t
)
deviceMemory
;
-
(
BOOL
)
smallMemoryDevice
;
@end
This diff is collapsed.
Click to expand it.
ios/Classes/1.0/Support/Memory/FLBMemoryInspector.mm
0 → 100755
View file @
5173dd21
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#import "FLBMemoryInspector.h"
#include <mach/mach.h>
#include <stdlib.h>
#include <sys/sysctl.h>
#define MB(_v_) (_v_*1024*1024)
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
@interface
FLBMemoryInspector
()
@property
(
nonatomic
,
assign
)
FLBMemoryCondition
condition
;
@end
@implementation
FLBMemoryInspector
+
(
instancetype
)
sharedInstance
{
static
id
sInstance
=
nil
;
static
dispatch_once_t
onceToken
;
dispatch_once
(
&
onceToken
,
^
{
sInstance
=
[[
self
.
class
alloc
]
init
];
});
return
sInstance
;
}
static
bool
isHighterThanIos9
(){
bool
ret
=
SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO
(
@"9.0.0"
);
return
ret
;
}
static
int64_t
memoryFootprint
()
{
task_vm_info_data_t
vmInfo
;
mach_msg_type_number_t
count
=
TASK_VM_INFO_COUNT
;
kern_return_t
result
=
task_info
(
mach_task_self
(),
TASK_VM_INFO
,
(
task_info_t
)
&
vmInfo
,
&
count
);
if
(
result
!=
KERN_SUCCESS
)
return
-
1
;
return
vmInfo
.
phys_footprint
;
}
static
int64_t
_memoryWarningLimit
()
{
size_t
size
;
sysctlbyname
(
"hw.machine"
,
NULL
,
&
size
,
NULL
,
0
);
char
*
machine
=
(
char
*
)
malloc
(
size
);
sysctlbyname
(
"hw.machine"
,
machine
,
&
size
,
NULL
,
0
);
NSString
*
platform
=
[
NSString
stringWithUTF8String
:
machine
];
free
(
machine
);
if
([
platform
isEqualToString
:
@"iPhone5,1"
])
return
MB
(
600
);
if
([
platform
isEqualToString
:
@"iPhone5,2"
])
return
MB
(
600
);
if
([
platform
isEqualToString
:
@"iPhone5,3"
])
return
MB
(
600
);
if
([
platform
isEqualToString
:
@"iPhone5,4"
])
return
MB
(
600
);
if
([
platform
isEqualToString
:
@"iPhone6,1"
])
return
MB
(
600
);
if
([
platform
isEqualToString
:
@"iPhone6,2"
])
return
MB
(
600
);
if
([
platform
isEqualToString
:
@"iPhone7,1"
])
return
MB
(
600
);
if
([
platform
isEqualToString
:
@"iPhone7,2"
])
return
MB
(
600
);
if
([
platform
isEqualToString
:
@"iPhone8,1"
])
return
MB
(
1280
);
if
([
platform
isEqualToString
:
@"iPhone8,2"
])
return
MB
(
1280
);
if
([
platform
isEqualToString
:
@"iPhone8,4"
])
return
MB
(
1280
);
if
([
platform
isEqualToString
:
@"iPhone9,1"
])
return
MB
(
1280
);
if
([
platform
isEqualToString
:
@"iPhone9,2"
])
return
MB
(
1950
);
if
([
platform
isEqualToString
:
@"iPhone9,3"
])
return
MB
(
1280
);
if
([
platform
isEqualToString
:
@"iPhone9,4"
])
return
MB
(
1950
);
if
([
platform
isEqualToString
:
@"iPhone10,1"
])
return
MB
(
1280
);
if
([
platform
isEqualToString
:
@"iPhone10,2"
])
return
MB
(
1950
);
if
([
platform
isEqualToString
:
@"iPhone10,3"
])
return
MB
(
1950
);
if
([
platform
isEqualToString
:
@"iPhone10,4"
])
return
MB
(
1280
);
if
([
platform
isEqualToString
:
@"iPhone10,5"
])
return
MB
(
1950
);
if
([
platform
isEqualToString
:
@"iPhone10,6"
])
return
MB
(
1950
);
return
0
;
}
static
int64_t
getLimit
(){
const
static
size_t
l
=
_memoryWarningLimit
();
return
l
;
}
-
(
int64_t
)
deviceMemory
{
int64_t
size
=
[
NSProcessInfo
processInfo
].
physicalMemory
;
return
size
;
}
-
(
BOOL
)
smallMemoryDevice
{
if
([
self
deviceMemory
]
<=
MB
(
1024
)){
return
YES
;
}
else
{
return
NO
;
}
}
-
(
FLBMemoryCondition
)
currentCondition
{
FLBMemoryCondition
newCondition
=
FLBMemoryConditionUnknown
;
if
(
!
isHighterThanIos9
()
||
getLimit
()
<=
0
){
newCondition
=
FLBMemoryConditionUnknown
;
}
else
if
(
memoryFootprint
()
<
getLimit
()
*
0.40
){
newCondition
=
FLBMemoryConditionNormal
;
}
else
if
(
memoryFootprint
()
<
getLimit
()
*
0.60
){
newCondition
=
FLBMemoryConditionLowMemory
;
}
else
if
(
memoryFootprint
()
<
getLimit
()
*
0.80
){
newCondition
=
FLBMemoryConditionExtremelyLow
;
}
else
{
newCondition
=
FLBMemoryConditionAboutToDie
;
}
if
(
newCondition
!=
self
.
condition
)
{
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
kFLBMemoryInspectorChangedNotification
object:
@{
kFLBMemoryInspectorKeyCondition
:
@
(
newCondition
)}];
}
self
.
condition
=
newCondition
;
return
newCondition
;
}
-
(
int64_t
)
currentFootPrint
{
return
memoryFootprint
();
}
@end
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment