Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b4a112e

Browse files
committed
iOS Log输出
1 parent 09dc20e commit b4a112e

File tree

6 files changed

+73
-2
lines changed

6 files changed

+73
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@
4242

4343
Android版安装包:[点击下载](https://www.pgyer.com/gYXj)
4444

45-
IOS需要自行下载代码运行。(效果是一致的)
45+
iOS需要自行下载代码运行。(效果是一致的)
4646

4747
**注意**
4848

4949
1. `debug`模式下会有部分卡顿现象,属于正常现象。良好的体验需要打`release` 包。
50-
IOS可以执行命令`flutter build ios` 以创建`release`版本。
50+
iOS可以执行命令`flutter build ios` 以创建`release`版本。
5151
Android可以执行命令`flutter build apk` 以创建`release`版本。
5252

5353
2. 因为页面有点多,不清楚业务流程可能会导致部分页面无法找到。具体可以参看设计图,或者页面上都随便点点。。。

ios/Podfile.lock

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@ PODS:
22
- flustars (0.0.1):
33
- Flutter
44
- Flutter (1.0.0)
5+
- FMDB (2.7.2):
6+
- FMDB/standard (= 2.7.2)
7+
- FMDB/standard (2.7.2)
58
- image_picker (0.0.1):
69
- Flutter
10+
- path_provider (0.0.1):
11+
- Flutter
712
- shared_preferences (0.0.1):
813
- Flutter
14+
- sqflite (0.0.1):
15+
- Flutter
16+
- FMDB (~> 2.7.2)
917
- url_launcher (0.0.1):
1018
- Flutter
1119
- webview_flutter (0.0.1):
@@ -15,19 +23,29 @@ DEPENDENCIES:
1523
- flustars (from `.symlinks/plugins/flustars/ios`)
1624
- Flutter (from `.symlinks/flutter/ios`)
1725
- image_picker (from `.symlinks/plugins/image_picker/ios`)
26+
- path_provider (from `.symlinks/plugins/path_provider/ios`)
1827
- shared_preferences (from `.symlinks/plugins/shared_preferences/ios`)
28+
- sqflite (from `.symlinks/plugins/sqflite/ios`)
1929
- url_launcher (from `.symlinks/plugins/url_launcher/ios`)
2030
- webview_flutter (from `.symlinks/plugins/webview_flutter/ios`)
2131

32+
SPEC REPOS:
33+
https://github.com/cocoapods/specs.git:
34+
- FMDB
35+
2236
EXTERNAL SOURCES:
2337
flustars:
2438
:path: ".symlinks/plugins/flustars/ios"
2539
Flutter:
2640
:path: ".symlinks/flutter/ios"
2741
image_picker:
2842
:path: ".symlinks/plugins/image_picker/ios"
43+
path_provider:
44+
:path: ".symlinks/plugins/path_provider/ios"
2945
shared_preferences:
3046
:path: ".symlinks/plugins/shared_preferences/ios"
47+
sqflite:
48+
:path: ".symlinks/plugins/sqflite/ios"
3149
url_launcher:
3250
:path: ".symlinks/plugins/url_launcher/ios"
3351
webview_flutter:
@@ -36,8 +54,11 @@ EXTERNAL SOURCES:
3654
SPEC CHECKSUMS:
3755
flustars: 0e81b1510ccac786ec044db1565e499b83e65da1
3856
Flutter: 9d0fac939486c9aba2809b7982dfdbb47a7b0296
57+
FMDB: 6198a90e7b6900cfc046e6bc0ef6ebb7be9236aa
3958
image_picker: 86b84c4fe89267356a1f17297a45b5d317ebd2e7
59+
path_provider: 09407919825bfe3c2deae39453b7a5b44f467873
4060
shared_preferences: 5a1d487c427ee18fcd3ea1f2a131569481834b53
61+
sqflite: d1612813fa7db7c667bed9f1d1b508deffc56999
4162
url_launcher: 92b89c1029a0373879933c21642958c874539095
4263
webview_flutter: 9bd234c07e99632356cba112df56fd1d47d6b6e3
4364

ios/Runner.xcodeproj/project.pbxproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
1313
3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; };
1414
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
15+
728E6F3C22C24CAC0036F6D1 /* PrintBeautifulLog in Resources */ = {isa = PBXBuildFile; fileRef = 728E6F3B22C24CAC0036F6D1 /* PrintBeautifulLog */; };
1516
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; };
1617
9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
1718
9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB21CF90195004384FC /* Debug.xcconfig */; };
@@ -43,6 +44,7 @@
4344
38907E1482E1004F8671A409 /* libPods-Runner.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Runner.a"; sourceTree = BUILT_PRODUCTS_DIR; };
4445
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
4546
3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; };
47+
728E6F3B22C24CAC0036F6D1 /* PrintBeautifulLog */ = {isa = PBXFileReference; lastKnownFileType = folder; name = PrintBeautifulLog; path = "../../../PrintBeautifulLog-master/PrintBeautifulLog"; sourceTree = "<group>"; };
4648
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
4749
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
4850
7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
@@ -113,6 +115,7 @@
113115
97C146F01CF9000F007C117D /* Runner */ = {
114116
isa = PBXGroup;
115117
children = (
118+
728E6F3B22C24CAC0036F6D1 /* PrintBeautifulLog */,
116119
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */,
117120
7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */,
118121
97C146FA1CF9000F007C117D /* Main.storyboard */,
@@ -186,6 +189,7 @@
186189
developmentRegion = English;
187190
hasScannedForEncodings = 0;
188191
knownRegions = (
192+
English,
189193
en,
190194
Base,
191195
);
@@ -209,6 +213,7 @@
209213
9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */,
210214
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */,
211215
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */,
216+
728E6F3C22C24CAC0036F6D1 /* PrintBeautifulLog in Resources */,
212217
);
213218
runOnlyForDeploymentPostprocessing = 0;
214219
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

ios/Runner/AppDelegate.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
#import <Flutter/Flutter.h>
22
#import <UIKit/UIKit.h>
33

4+
#ifdef DEBUG
5+
6+
#define XLog(FORMAT, ...) fprintf(stderr, "%s:%d\t%s\n", [[[NSString stringWithUTF8String: __FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat: FORMAT, ## __VA_ARGS__] UTF8String]);
7+
8+
#else
9+
10+
#define XLog(FORMAT, ...) nil
11+
12+
#endif
13+
414
@interface AppDelegate : FlutterAppDelegate
515

616
@end

ios/Runner/AppDelegate.m

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,33 @@ @implementation AppDelegate
66
- (BOOL)application:(UIApplication *)application
77
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
88
[GeneratedPluginRegistrant registerWithRegistry:self];
9+
10+
FlutterViewController *controller = (FlutterViewController*)self.window.rootViewController;
11+
12+
FlutterMethodChannel *logChannel = [FlutterMethodChannel methodChannelWithName:@"x_log" binaryMessenger:controller];
13+
14+
[logChannel setMethodCallHandler:^(FlutterMethodCall * _Nonnull call, FlutterResult _Nonnull result) {
15+
NSString *tag = call.arguments[@"tag"];
16+
NSString *msg = call.arguments[@"msg"];
17+
if ([call.method isEqualToString:@"logJson"]) {
18+
NSData *jsonData = [msg dataUsingEncoding:NSUTF8StringEncoding];
19+
20+
NSError *err;
21+
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
22+
options:NSJSONReadingMutableContainers
23+
error:&err];
24+
if(err){
25+
XLog(@"%@%@", tag, msg);
26+
}else{
27+
XLog(@"%@%@", tag, dic);
28+
}
29+
30+
}else{
31+
XLog(@"%@%@", tag, msg);
32+
}
33+
34+
}];
35+
936
// Override point for customization after application launch.
1037
return [super application:application didFinishLaunchingWithOptions:launchOptions];
1138
}

0 commit comments

Comments
 (0)