Advertisement
JustItaly

iPhone error

Feb 10th, 2023
1,178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 7.77 KB | Source Code | 0 0
  1. import 'dart:async';
  2. import 'dart:io' show Platform;
  3.  
  4. import 'package:flutter/foundation.dart';
  5. import 'package:flutter/services.dart';
  6. import 'package:location_permissions/location_permissions.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
  9.  
  10. void main() {
  11.   return runApp(
  12.     const MaterialApp(home: HomePage()),
  13.   );
  14. }
  15.  
  16. class HomePage extends StatefulWidget {
  17.   const HomePage({Key? key}) : super(key: key);
  18.  
  19.   @override
  20.   HomePageState createState() => HomePageState();
  21. }
  22.  
  23. class HomePageState extends State<HomePage> {
  24.   bool foundDeviceWaitingToConnect = false;
  25.   bool scanStarted = false;
  26.   bool connected = false;
  27. // Bluetooth related variables
  28.   late DiscoveredDevice ubiqueDevice;
  29.   final flutterReactiveBle = FlutterReactiveBle();
  30.   late StreamSubscription<DiscoveredDevice> scanStream;
  31.   late QualifiedCharacteristic rxCharacteristic;
  32. // These are the UUIDs of your device
  33.   final Uuid serviceUuid = Uuid.parse("75C276C3-8F97-20BC-A143-B354244886D4");
  34.   final Uuid characteristicUuid =
  35.       Uuid.parse("6ACF4F08-CC9D-D495-6B41-AA7E60C4E8A6");
  36.  
  37.   void startScan() async {
  38.     // Platform permissions handling stuff
  39.     if (kDebugMode) {
  40.       print("Start scanning...");
  41.     }
  42.     bool permGranted = false;
  43.     setState(() {
  44.       scanStarted = true;
  45.     });
  46.     PermissionStatus permission;
  47.     if (kDebugMode) {
  48.       print(Platform.operatingSystem);
  49.       print(Platform.localeName);
  50.     }
  51.     if (Platform.isAndroid) {
  52.       permission = await LocationPermissions().requestPermissions();
  53.       if (permission == PermissionStatus.granted) permGranted = true;
  54.     } else if (Platform.isIOS) {
  55.       permGranted = true;
  56.     }
  57.     // Main scanning logic happens here โคต๏ธ
  58.     if (permGranted) {
  59.       if (kDebugMode) {
  60.         print("Permission granted, waiting BLE devices...");
  61.       }
  62.       scanStream = flutterReactiveBle
  63.           .scanForDevices(withServices: [serviceUuid]).listen((device) {
  64.         // Change this string to what you defined in Zephyr
  65.         if (device.name == 'HyperTorcia') {
  66.           setState(() {
  67.             ubiqueDevice = device;
  68.             foundDeviceWaitingToConnect = true;
  69.           });
  70.           connectToDevice();
  71.         }
  72.       });
  73.     }
  74.   }
  75.  
  76.   void connectToDevice() {
  77.     // We're done scanning, we can cancel it
  78.     scanStream.cancel();
  79.     // Let's listen to our connection so we can make updates on a state change
  80.     Stream<ConnectionStateUpdate> currentConnectionStream = flutterReactiveBle
  81.         .connectToAdvertisingDevice(
  82.             id: ubiqueDevice.id,
  83.             prescanDuration: const Duration(seconds: 1),
  84.             withServices: [serviceUuid, characteristicUuid]);
  85.     currentConnectionStream.listen((event) {
  86.       switch (event.connectionState) {
  87.         // We're connected and good to go!
  88.         case DeviceConnectionState.connected:
  89.           {
  90.             rxCharacteristic = QualifiedCharacteristic(
  91.                 serviceId: serviceUuid,
  92.                 characteristicId: characteristicUuid,
  93.                 deviceId: event.deviceId);
  94.             setState(() {
  95.               foundDeviceWaitingToConnect = false;
  96.               connected = true;
  97.             });
  98.             break;
  99.           }
  100.         // Can add various state state updates on disconnect
  101.         case DeviceConnectionState.disconnected:
  102.           {
  103.             break;
  104.           }
  105.         default:
  106.       }
  107.     });
  108.   }
  109.  
  110.   void partyTime() {
  111.     if (connected) {
  112.       flutterReactiveBle
  113.           .writeCharacteristicWithResponse(rxCharacteristic, value: [
  114.         0x02,
  115.       ]);
  116.     }
  117.   }
  118.  
  119.   @override
  120.   Widget build(BuildContext context) {
  121.     return Scaffold(
  122.       backgroundColor: Colors.white,
  123.       body: Container(),
  124.       persistentFooterButtons: [
  125.         // We want to enable this button if the scan has NOT started
  126.         // If the scan HAS started, it should be disabled.
  127.         scanStarted
  128.             // True condition
  129.             ? ElevatedButton(
  130.                 style: ElevatedButton.styleFrom(
  131.                   backgroundColor: Colors.grey, // background
  132.                   foregroundColor: Colors.white, // foreground
  133.                 ),
  134.                 onPressed: () {},
  135.                 child: const Icon(Icons.search),
  136.               )
  137.             // False condition
  138.             : ElevatedButton(
  139.                 style: ElevatedButton.styleFrom(
  140.                   backgroundColor: Colors.blue, // background
  141.                   foregroundColor: Colors.white, // foreground
  142.                 ),
  143.                 onPressed: startScan,
  144.                 child: const Icon(Icons.search),
  145.               ),
  146.         foundDeviceWaitingToConnect
  147.             // True condition
  148.             ? ElevatedButton(
  149.                 style: ElevatedButton.styleFrom(
  150.                   backgroundColor: Colors.blue, // background
  151.                   foregroundColor: Colors.white, // foreground
  152.                 ),
  153.                 onPressed: connectToDevice,
  154.                 child: const Icon(Icons.bluetooth),
  155.               )
  156.             // False condition
  157.             : ElevatedButton(
  158.                 style: ElevatedButton.styleFrom(
  159.                   backgroundColor: Colors.grey, // background
  160.                   foregroundColor: Colors.white, // foreground
  161.                 ),
  162.                 onPressed: () {},
  163.                 child: const Icon(Icons.bluetooth),
  164.               ),
  165.         connected
  166.             // True condition
  167.             ? ElevatedButton(
  168.                 style: ElevatedButton.styleFrom(
  169.                   backgroundColor: Colors.blue, // background
  170.                   foregroundColor: Colors.white, // foreground
  171.                 ),
  172.                 onPressed: partyTime,
  173.                 child: const Icon(Icons.celebration_rounded),
  174.               )
  175.             // False condition
  176.             : ElevatedButton(
  177.                 style: ElevatedButton.styleFrom(
  178.                   backgroundColor: Colors.grey, // background
  179.                   foregroundColor: Colors.white, // foreground
  180.                 ),
  181.                 onPressed: () {},
  182.                 child: const Icon(Icons.celebration_rounded),
  183.               ),
  184.       ],
  185.     );
  186.   }
  187. }
  188.  
  189. Errore generato nell'iPhone con OSX 16.3:
  190.  
  191. Launching lib/main.dart on iPhone di Keres in debug mode...
  192. Automatically signing iOS for device deployment using specified development team in Xcode project: RCT45BYNT4
  193. Xcode build done.                                            8,7s
  194. (lldb) 2023-02-10 15:04:58.521031+0100 Runner[27335:9898606] [SceneConfiguration] Info.plist contained no UIScene configuration dictionary (looking for configuration named "(no name)")
  195. Warning: Unable to create restoration in progress marker file
  196. Connecting to VM Service at ws://127.0.0.1:50826/HAdtjnhysow=/ws
  197. fopen failed for data file: errno = 2 (No such file or directory)
  198. Errors found! Invalidating cache...
  199. fopen failed for data file: errno = 2 (No such file or directory)
  200. Errors found! Invalidating cache...
  201. flutter: Start scanning...
  202. flutter: ios
  203. flutter: it_IT
  204. flutter: Permission granted, waiting BLE devices...
  205. Warning! No event channel set up to report a connection update
  206. reactive_ble_mobile/ConnectTaskController.swift:16: Assertion failed
  207. reactive_ble_mobile/ConnectTaskController.swift:16: Assertion failed
  208. * thread #1, queue = 'com.apple.main-thread', stop reason = Assertion failed
  209.    frame #0: 0x00000001cc9b10f8 libswiftCore.dylib`_swift_runtime_on_report
  210. libswiftCore.dylib`:
  211. ->  0x1cc9b10f8 <+0>: ret
  212. libswiftCore.dylib`:
  213.    0x1cc9b10fc <+0>: b      0x1cc9b10f8               ; _swift_runtime_on_report
  214. libswiftCore.dylib`:
  215.    0x1cc9b1100 <+0>: adrp   x8, 365868
  216.    0x1cc9b1104 <+4>: ldrb   w0, [x8, #0xabc]
  217. Target 0: (Runner) stopped.
  218. Lost connection to device.
  219. Exited
  220.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement