Skip to content

Commit 68ce2cb

Browse files
jung hyun kojung hyun ko
jung hyun ko
authored and
jung hyun ko
committed
swift test ...
1 parent a9c9f16 commit 68ce2cb

File tree

6 files changed

+101
-100
lines changed

6 files changed

+101
-100
lines changed

example/ios/Runner.xcodeproj/project.pbxproj

+7-4
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
97C146E61CF9000F007C117D /* Project object */ = {
156156
isa = PBXProject;
157157
attributes = {
158-
LastUpgradeCheck = 1020;
158+
LastUpgradeCheck = 1240;
159159
ORGANIZATIONNAME = "";
160160
TargetAttributes = {
161161
97C146ED1CF9000F007C117D = {
@@ -321,6 +321,7 @@
321321
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
322322
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
323323
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
324+
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
324325
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
325326
CLANG_WARN_STRICT_PROTOTYPES = YES;
326327
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -339,7 +340,7 @@
339340
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
340341
GCC_WARN_UNUSED_FUNCTION = YES;
341342
GCC_WARN_UNUSED_VARIABLE = YES;
342-
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
343+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
343344
MTL_ENABLE_DEBUG_INFO = NO;
344345
SDKROOT = iphoneos;
345346
SUPPORTED_PLATFORMS = iphoneos;
@@ -393,6 +394,7 @@
393394
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
394395
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
395396
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
397+
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
396398
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
397399
CLANG_WARN_STRICT_PROTOTYPES = YES;
398400
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -417,7 +419,7 @@
417419
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
418420
GCC_WARN_UNUSED_FUNCTION = YES;
419421
GCC_WARN_UNUSED_VARIABLE = YES;
420-
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
422+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
421423
MTL_ENABLE_DEBUG_INFO = YES;
422424
ONLY_ACTIVE_ARCH = YES;
423425
SDKROOT = iphoneos;
@@ -448,6 +450,7 @@
448450
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
449451
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
450452
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
453+
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
451454
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
452455
CLANG_WARN_STRICT_PROTOTYPES = YES;
453456
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -466,7 +469,7 @@
466469
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
467470
GCC_WARN_UNUSED_FUNCTION = YES;
468471
GCC_WARN_UNUSED_VARIABLE = YES;
469-
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
472+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
470473
MTL_ENABLE_DEBUG_INFO = NO;
471474
SDKROOT = iphoneos;
472475
SUPPORTED_PLATFORMS = iphoneos;

example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1020"
3+
LastUpgradeVersion = "1240"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -27,8 +27,6 @@
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
2929
shouldUseLaunchSchemeArgsEnv = "YES">
30-
<Testables>
31-
</Testables>
3230
<MacroExpansion>
3331
<BuildableReference
3432
BuildableIdentifier = "primary"
@@ -38,8 +36,8 @@
3836
ReferencedContainer = "container:Runner.xcodeproj">
3937
</BuildableReference>
4038
</MacroExpansion>
41-
<AdditionalOptions>
42-
</AdditionalOptions>
39+
<Testables>
40+
</Testables>
4341
</TestAction>
4442
<LaunchAction
4543
buildConfiguration = "Debug"
@@ -61,8 +59,6 @@
6159
ReferencedContainer = "container:Runner.xcodeproj">
6260
</BuildableReference>
6361
</BuildableProductRunnable>
64-
<AdditionalOptions>
65-
</AdditionalOptions>
6662
</LaunchAction>
6763
<ProfileAction
6864
buildConfiguration = "Profile"

ios/Classes/ProximitySensorPlugin.h

-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,3 @@
22

33
@interface ProximitySensorPlugin : NSObject<FlutterPlugin>
44
@end
5-
6-
@interface ProximityStreamHandler : NSObject<FlutterStreamHandler>
7-
@end

ios/Classes/ProximitySensorPlugin.m

+6-64
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,20 @@
1-
21
#import <Foundation/Foundation.h>
32
#import "ProximitySensorPlugin.h"
43

5-
//#if __has_include(<proximity_sensor/proximity_sensor-Swift.h>)
6-
//#import <proximity_sensor/proximity_sensor-Swift.h>
7-
//#else
4+
#if __has_include(<proximity_sensor/proximity_sensor-Swift.h>)
5+
#import <proximity_sensor/proximity_sensor-Swift.h>
6+
#else
87
// Support project import fallback if the generated compatibility header
98
// is not copied when this plugin is created as a library.
109
// https://forums.swift.org/t/swift-static-libraries-dont-copy-generated-objective-c-header/19816
11-
//#import "proximity_sensor-Swift.h"
12-
//#endif
10+
#import "proximity_sensor-Swift.h"
11+
#endif
1312

1413
////////////////////////////////////////////////////////////////////////////////
1514
@implementation ProximitySensorPlugin
1615
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
17-
18-
ProximityStreamHandler* handler = [[ProximityStreamHandler alloc] init];
19-
FlutterEventChannel* channel = [FlutterEventChannel eventChannelWithName:@"proximity_sensor"
20-
binaryMessenger:[registrar messenger]];
21-
[channel setStreamHandler: handler];
22-
//messenger returns a `FlutterBinaryMessenger` for creating Dart/iOS communication
23-
//channels to be used by the plugin.
24-
25-
//---------------------------------------------------------- TODO
26-
//[SwiftProximitySensorPlugin registerWithRegistrar:registrar];
16+
[SwiftProximitySensorPlugin registerWithRegistrar:registrar];
2717
}
2818
@end
2919

30-
////////////////////////////////////////////////////////////////////////////////
31-
NSNotificationCenter* observer;
32-
@implementation ProximityStreamHandler
33-
34-
//Sets up an event stream and begin emitting events.
35-
//Invoked when the first listener is registered with the Stream associated to
36-
//this channel on the Flutter side.
37-
38-
- (FlutterError *)onListenWithArguments:(id)arguments eventSink:(FlutterEventSink)events {
39-
40-
UIDevice* device = [UIDevice currentDevice];
41-
//먼저 센서 값을 일단 보내고..
42-
device.proximityMonitoringEnabled = YES;
43-
int onoff = device.proximityState ? 0 : 1 ;
44-
NSMutableData * data = [NSMutableData dataWithCapacity: 1 * sizeof(int)];
45-
[data appendBytes: &onoff length:sizeof(int)];
46-
events([FlutterStandardTypedData typedDataWithInt32:data]); //function pointer..
47-
48-
//queue 에 저장해서 계속 전송하게 한다
49-
NSOperationQueue * sensor_queue = [ NSOperationQueue mainQueue]; //Returns the operation queue associated with the main thread.
50-
observer = [[NSNotificationCenter defaultCenter] addObserverForName:UIDeviceProximityStateDidChangeNotification
51-
object:nil
52-
queue:sensor_queue
53-
//queue:nil //TEST XXX
54-
usingBlock: ^(NSNotification* noti){
55-
UIDevice* device = [UIDevice currentDevice];
56-
int onoff = device.proximityState ? 0 : 1 ;
57-
NSLog(@"onoff=%d\n", onoff);
58-
59-
60-
NSMutableData * data = [NSMutableData dataWithCapacity: 1 * sizeof(int)];
61-
[data appendBytes: &onoff length:sizeof(int)];
62-
events([FlutterStandardTypedData typedDataWithInt32:data]); //function pointer..
63-
} ] ;
64-
return nil;
65-
}
6620

67-
//Tears down an event stream.
68-
//Invoked when the last listener is deregistered from the Stream associated to
69-
//this channel on the Flutter side.
70-
- (FlutterError *)onCancelWithArguments:(id)arguments{
71-
UIDevice* device = [UIDevice currentDevice];
72-
device.proximityMonitoringEnabled = NO;
73-
[[NSNotificationCenter defaultCenter] removeObserver:observer
74-
name:UIDeviceProximityStateDidChangeNotification
75-
object:nil];
76-
return nil;
77-
}
78-
@end

ios/Classes/SwiftProximitySensorPlugin.swift

+83-20
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,91 @@ import Flutter
22
import UIKit
33

44
//https://flutterdevs.com/blog/creating-a-flutter-plugin-for-android-and-ios-image-gallery/
5-
/*
6-
public class SwiftProximitySensorPlugin: NSObject, FlutterPlugin {
7-
8-
public static func register(with registrar: FlutterPluginRegistrar) {
9-
//UIDevice.current.isProximityMonitoringEnabled = true
5+
6+
public class SwiftProximityStreamHandler : NSObject,FlutterStreamHandler
7+
{
8+
public func onListen(withArguments arguments: Any?, eventSink events: @escaping FlutterEventSink) -> FlutterError? {
9+
let device = UIDevice.current
10+
device.isProximityMonitoringEnabled = true
11+
//NotificationCenter.default.addObserver(forName: <#T##NSNotification.Name?#>, object: <#T##Any?#>, queue: <#T##OperationQueue?#>, using: <#T##(Notification) -> Void#>)
12+
NotificationCenter.default.addObserver(forName: UIDevice.proximityStateDidChangeNotification, object: device, queue: nil)
13+
{ /* [weak self] */ (notification) in
14+
//guard let strongSelf = self else { return }
15+
if let device = notification.object as? UIDevice {
16+
print("from swift ...")
17+
// Int32 type 인 경우 dart 에서 수신하는 것은 4 byte: this is dart code --> [0, 0, 0, 0]
18+
// --> dart 에서 처리시 list 로! 즉, return new ProximityEvent(event.cast<int>()[0]);
19+
// Int8 type 인 경우 dart 에서 수신하는 것은 1 byte: this is dart code --> [0]
20+
// --> 이경우에는 dart 코드에서는 리스트로 처리 안해도 됨 !
21+
// return new ProximityEvent(event.cast<int>());
22+
let onoff:Int8 = device.proximityState ? 0 : 1
23+
print(onoff)
24+
var data = Data()
25+
withUnsafeBytes(of: onoff) {buffer in data.append(buffer.bindMemory(to: Int8.self))}
26+
events(data)
27+
}
28+
}
29+
////////////////
30+
/*
31+
NotificationCenter.default.addObserver(self, selector: #selector(proximityStateDidChange),
32+
name: UIDevice.proximityStateDidChangeNotification,
33+
object: device)
34+
*/
35+
return nil
36+
}
1037

11-
let channel = FlutterMethodChannel(name: "proximity_sensor", binaryMessenger: registrar.messenger())
12-
let instance = SwiftProximitySensorPlugin()
13-
registrar.addMethodCallDelegate(instance, channel: channel)
14-
}
38+
public func onCancel(withArguments arguments: Any?) -> FlutterError? {
39+
//TODO
40+
return nil
41+
}
42+
/*
43+
@objc func proximityStateDidChange(notification: Notification)
44+
{
45+
if let device = notification.object as? UIDevice {
46+
print("from swift ...")
47+
print( device)
48+
}
49+
}
50+
*/
51+
}
52+
53+
public class SwiftProximitySensorPlugin: NSObject, FlutterPlugin
54+
{
55+
//static var observer:NotificationCenter = NotificationCenter.default
56+
static var stream_handler:SwiftProximityStreamHandler = SwiftProximityStreamHandler()
57+
static var channel:FlutterEventChannel = FlutterEventChannel()
1558

16-
//////////////////////////////////////////////////////////////////////////////
17-
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
18-
//result("iOS " + UIDevice.current.systemVersion)
19-
//getProximityOnOff
20-
//result(UIDevice.current.proximityState)
59+
public static func register(with registrar: FlutterPluginRegistrar)
60+
{
61+
//---------------------------- FlutterEventChannel
62+
let channel = FlutterEventChannel.init(name: "proximity_sensor", binaryMessenger: registrar.messenger())
63+
channel.setStreamHandler(stream_handler)
64+
//----------------------------
65+
//auto generated code ...!
66+
/*
67+
let channel = FlutterMethodChannel(name: "proximity_sensor", binaryMessenger: registrar.messenger())
68+
let instance = SwiftProximitySensorPlugin()
69+
registrar.addMethodCallDelegate(instance, channel: channel)
70+
*/
71+
}
2172

22-
if call.method == "getProximityOnOff" {
23-
result(UIDevice.current.proximityState)
73+
/*
74+
public func detachFromEngine(for registrar: FlutterPluginRegistrar) {
75+
let device = UIDevice.current
76+
device.isProximityMonitoringEnabled = false
77+
NotificationCenter.default.removeObserver(observer)
78+
}
79+
*/
80+
//////////////////////////////////////////////////////////////////////////////
81+
// - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result;
82+
// Called if this plugin has been registered to receive `FlutterMethodCall`s.
83+
// @param call The method call command object.
84+
// @param result A callback for submitting the result of the call.
85+
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
86+
NSLog(call.method) //"listen"
87+
if call.method == "listen" {
88+
}
89+
//result("iOS " + UIDevice.current.systemVersion)
2490
}
25-
26-
//FlutterStreamHandler
27-
}
2891
}
29-
*/
92+

lib/proximity_sensor.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ class ProximitySensor {
4141
//.map((event) => new ProximityEvent(event.cast<int>()));
4242
.map((event) {
4343
print("this is dart code --> " + event.toString());
44-
return new ProximityEvent(event.cast<int>()[0]); //XXX XXX XXX
44+
//return new ProximityEvent(event.cast<int>()[0]); //XXX android 에서는 몇바이트로 넘겨주는지 확인해야.
4545

46-
//return new ProximityEvent(event.cast<int>());
46+
return new ProximityEvent(event.cast<int>()); // 1 byte 를 넘겨주는 경우에 가능.
4747
//--> list<int,int..>
4848
//XXX XXX XXX error 안됨. list 임.!
4949
//--> Unhandled Exception: type 'CastList<int, int>' is not a subtype of type 'int'

0 commit comments

Comments
 (0)