提交 53876ac0 authored 作者: jiangjun's avatar jiangjun

ios 加入初始化方法

上级 c00cb0fe
# Uncomment this line to define a global platform for your project
# platform :ios, '11.0'
platform :ios, '11.0'
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
......
......@@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
6B2C50D08C38BDFEA3BF1C44 /* libPods-Runner.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 87B7A136E7CC1EE7A22A97F2 /* libPods-Runner.a */; };
978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; };
97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; };
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
......@@ -33,9 +34,11 @@
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
526DFD31B7C3A2B625F87E65 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
87B7A136E7CC1EE7A22A97F2 /* libPods-Runner.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Runner.a"; sourceTree = BUILT_PRODUCTS_DIR; };
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; };
......@@ -44,6 +47,8 @@
97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
C7DC19D49AEB0150D79397A4 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
F420B3B5C7E263F2D4035105 /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -51,12 +56,21 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
6B2C50D08C38BDFEA3BF1C44 /* libPods-Runner.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
2E5DEE9B092EE420B32B9721 /* Frameworks */ = {
isa = PBXGroup;
children = (
87B7A136E7CC1EE7A22A97F2 /* libPods-Runner.a */,
);
name = Frameworks;
sourceTree = "<group>";
};
9740EEB11CF90186004384FC /* Flutter */ = {
isa = PBXGroup;
children = (
......@@ -74,6 +88,8 @@
9740EEB11CF90186004384FC /* Flutter */,
97C146F01CF9000F007C117D /* Runner */,
97C146EF1CF9000F007C117D /* Products */,
D85D3940D8E6D86998718794 /* Pods */,
2E5DEE9B092EE420B32B9721 /* Frameworks */,
);
sourceTree = "<group>";
};
......@@ -109,6 +125,17 @@
name = "Supporting Files";
sourceTree = "<group>";
};
D85D3940D8E6D86998718794 /* Pods */ = {
isa = PBXGroup;
children = (
526DFD31B7C3A2B625F87E65 /* Pods-Runner.debug.xcconfig */,
C7DC19D49AEB0150D79397A4 /* Pods-Runner.release.xcconfig */,
F420B3B5C7E263F2D4035105 /* Pods-Runner.profile.xcconfig */,
);
name = Pods;
path = Pods;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
......@@ -116,6 +143,7 @@
isa = PBXNativeTarget;
buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */;
buildPhases = (
77BDFA17859FD29518F1CFC8 /* [CP] Check Pods Manifest.lock */,
9740EEB61CF901F6004384FC /* Run Script */,
97C146EA1CF9000F007C117D /* Sources */,
97C146EB1CF9000F007C117D /* Frameworks */,
......@@ -194,6 +222,28 @@
shellPath = /bin/sh;
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin";
};
77BDFA17859FD29518F1CFC8 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputFileListPaths = (
);
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
......
......@@ -4,4 +4,7 @@
<FileRef
location = "group:Runner.xcodeproj">
</FileRef>
<FileRef
location = "group:Pods/Pods.xcodeproj">
</FileRef>
</Workspace>
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:hi_bugly/hi_bugly.dart';
void main() {
......@@ -16,35 +14,10 @@ class MyApp extends StatefulWidget {
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
final _hiBuglyPlugin = HiBugly();
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
platformVersion = await _hiBuglyPlugin.getPlatformVersion() ??
'Unknown platform version';
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
@override
......@@ -56,10 +29,9 @@ class _MyAppState extends State<MyApp> {
),
body: Column(
children: [
Text('Running on: $_platformVersion\n'),
MaterialButton(
onPressed: () {
_hiBuglyPlugin.initialize(appID: '123456', debug: true);
HiBugly.initialize(appID: '123456', debug: true);
},
child: const Text('初始化'),
),
......
#import "HiBuglyPlugin.h"
#import <Bugly/Bugly.h>
@implementation HiBuglyPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
FlutterMethodChannel* channel = [FlutterMethodChannel
methodChannelWithName:@"hi_bugly"
binaryMessenger:[registrar messenger]];
HiBuglyPlugin* instance = [[HiBuglyPlugin alloc] init];
[registrar addMethodCallDelegate:instance channel:channel];
FlutterMethodChannel* channel = [FlutterMethodChannel
methodChannelWithName:@"hi_bugly"
binaryMessenger:[registrar messenger]];
HiBuglyPlugin* instance = [[HiBuglyPlugin alloc] init];
[registrar addMethodCallDelegate:instance channel:channel];
}
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
if ([@"getPlatformVersion" isEqualToString:call.method]) {
result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]);
if ([@"initialize" isEqualToString:call.method]) {
NSString *appID = call.arguments[@"appID"];
BOOL debug = call.arguments[@"debug"];
BuglyConfig *config = [[BuglyConfig alloc] init];
config.debugMode = debug;
[Bugly startWithAppId:appID config: config];
result([NSNumber numberWithBool:YES]);
} else {
result(FlutterMethodNotImplemented);
result(FlutterMethodNotImplemented);
}
}
......
......@@ -20,4 +20,6 @@ A new Flutter project.
# Flutter.framework does not contain a i386 slice.
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
# bugly 依赖
s.dependency 'Bugly', '2.5.93'
end
import 'hi_bugly_platform_interface.dart';
class HiBugly {
Future<String?> getPlatformVersion() {
return HiBuglyPlatform.instance.getPlatformVersion();
}
Future<bool?> initialize({
static Future<bool?> initialize({
required String appID,
bool debug = false,
}) {
......
......@@ -9,13 +9,6 @@ class MethodChannelHiBugly extends HiBuglyPlatform {
@visibleForTesting
final methodChannel = const MethodChannel('hi_bugly');
@override
Future<String?> getPlatformVersion() async {
final version =
await methodChannel.invokeMethod<String>('getPlatformVersion');
return version;
}
@override
Future<bool?> initialize({
required String appID,
......
......@@ -23,10 +23,6 @@ abstract class HiBuglyPlatform extends PlatformInterface {
_instance = instance;
}
Future<String?> getPlatformVersion() {
throw UnimplementedError('platformVersion() has not been implemented.');
}
Future<bool?> initialize({
required String appID,
bool debug = false,
......
......@@ -18,7 +18,4 @@ void main() {
channel.setMockMethodCallHandler(null);
});
test('getPlatformVersion', () async {
expect(await platform.getPlatformVersion(), '42');
});
}
import 'package:flutter_test/flutter_test.dart';
import 'package:hi_bugly/hi_bugly.dart';
import 'package:hi_bugly/hi_bugly_platform_interface.dart';
import 'package:hi_bugly/hi_bugly_method_channel.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
......@@ -7,9 +6,6 @@ import 'package:plugin_platform_interface/plugin_platform_interface.dart';
class MockHiBuglyPlatform
with MockPlatformInterfaceMixin
implements HiBuglyPlatform {
@override
Future<String?> getPlatformVersion() => Future.value('42');
@override
Future<bool?> initialize({
required appID,
......@@ -26,12 +22,4 @@ void main() {
test('$MethodChannelHiBugly is the default instance', () {
expect(initialPlatform, isInstanceOf<MethodChannelHiBugly>());
});
test('getPlatformVersion', () async {
HiBugly hiBuglyPlugin = HiBugly();
MockHiBuglyPlatform fakePlatform = MockHiBuglyPlatform();
HiBuglyPlatform.instance = fakePlatform;
expect(await hiBuglyPlugin.getPlatformVersion(), '42');
});
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论