Flutter - Is there any way to restart iOS version programmatically? - ios

I have an flutter app and i used applifecyclestate.resumed to see if the app is running in the background and I used restart_app library to restart the app when it is in the background.This function worked in android but in ios it is not working
If you please tell is there anyway to restart the application in ios devices?
Here is the code
void didChangeAppLifecycleState(AppLifecycleState state) {
super.didChangeAppLifecycleState(state);
if (state == AppLifecycleState.resumed) {
debugPrint('----------> app state resumed');
Restart.restartApp();
}
Thank you

Related

Expo iOS simulator doesn't automatically refresh React Native app upon code changes

I'm using Expo's iOS simulator with my React Native app. Before, it would live update / "fast refresh" when code changes were made, but it's no longer doing that. So this is not about using the Expo Go app on my phone, but rather the Simulator on my Macbook.
I've checked the shake (ctrl + cmd + Z) menu, and Fast Refresh is still enabled. Running npx expo run:ios does correctly reflect the latest code, but that takes a while to run.
Any help to debug this?
A few days ago the same thing happened to me and it depended on how I exported the main component to App.tsx.
This one doesn't work properly:
export default () => {
return <View/>
}
This one works:
const App = () => {
return <View/>
}
export default App
Let me know if this helps

Bluetooth scan not work when using flutter in ios

I'm using flutter_blue_plus package which is almost same with flutter_blue. When I test with iphone 13 mini connected with mac book xcode, my app scans bluetooth devices well. But when I extract my app to .ipa and install the app using xcode, my iphone 13 mini(which is not connected to mac book) not scan bluetooth devices anymore. Of course I've checked that I give same permission to the iphone both of the test.
Is there any suggestion for test or anyone experienced same situation?
I'm very beginner of flutter and ios development (I just started it from a month ago), so please give me any advice if you have about this bluetooth problem..
My scan function is in the background mode, and I checked the scanned devices using snack bar. But I think it is not the problem, the app works well when I test with xcode and the iphone is connected to mac.
I added a part of my code for your information.
(My function for BLE Scanning)
Future<void> initialScanning() async {
// ios execute this function with .ipa installed but skips scanning.
final FlutterBluePlus flutterBlue = FlutterBluePlus.instance;
// Start scanning
flutterBlue.startScan(timeout: Duration(seconds: _firstScanDuration));
// Listen to scan results
var subscription = flutterBlue.scanResults.listen((results) async {
// Find the device with the name and Register
for (ScanResult r in results) {
print('${r.device.name} rssi: ${r.rssi}');
if (r.device.name == 'raspberrypi') {
if (!devices.contains(r.device)) {
devices.add(r.device);
print('device added!!!!');
}
}
}
for (BluetoothDevice device in devices) {
if (!registeredDevices.contains(device.id.toString())) {
registeredDevices.add(device.id.toString());
await someBleRegister(device);
}
}
});
// Stop scanning
flutterBlue.stopScan();
}
(onEvent function for flutter_foreground_task)
#override
Future<void> onEvent(DateTime timestamp, SendPort? sendPort) async {
if (_eventCount == 0) {
await initialScanning();
} else {
print('number of devices: ${someBles.length}');
for (SomeBle ble in someRegisteredBles) {
await someBleReadAndWrite(ble);
}
}
I my self found out the answer that flutter_blue_plus.startScan (i.e. BLE scan) is not work well with flutter_foreground_task package in ios.
When I use the startScan in onStart( a override method of flutter_foreground_task package), the BLE scanning was work well with normal development setup with xcode.
But the same code was not work when I made .ipa file and installed to iphone.
It never scans anything and skips the scanning.
But when I moved the BLE scanning codes to the foreground, it worked well both xcode connected and .ipa file installed.
I don't know why.. but, anyway, that is true.
(Edit) flutter_reactive_ble not work too in flutter_foreground_task background mode with .ipa file installed.

expo react native on ios setState is not working

here in this code none of the state inside if condition is working on ios but its working on android phones. I am using expo go app for working ios/android.
ProfileService.getDashboardInfo(res,0).then(res=>{
if(res?.success){
setloading(false)
setdashboardInfo(res?.data)
setCount(res?.data?.pendingJobs)
}
})
any kind of suggestions will be appreciated.

Flutter Firebase_messaging onBackgroundMessage is not called on older ios devices (iPhone 7 iPhone 8)

We are using firebase_messaging ^9.1.1 in our flutter app. onBackgroundMessage is being called in 'iPhone se' when app is in background or in terminated state. But is in not being called on iPhone 7 or iPhone 8. IOS version is same in all the devices i.e. IOS 14.4.2.
We are calling callkeep: ^0.2.3+1 plugin in onBackgroundMessage. We can't see call UI when app is terminated/in background and receive notification (iPhone 7 or iPhone 8).
This is our code:
void main() async {
FirebaseMessaging.onBackgroundMessage(myBackgroundMessageHandler);
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
if (!UniversalPlatform.isWeb) {
PushNotificationsManager().initCallKit();
}
Future<dynamic> myBackgroundMessageHandler(RemoteMessage message) async {
await Firebase.initializeApp();
//callkeep: ^0.2.3+1 plugin. code here.
}
Have anyone faced this issue? what next we can try to solve this issue?

Detecting app run on emulator or real device

I need to detect, if an app is running on an iOS or Android emulator to skip an QR code scan method and just return a scanned code.
Q: How do I detect
on which device type - iOS or Android - an app is running and
if an app is running on an emulator?
Just found this plugin, which prints various details:
https://pub.dartlang.org/packages/device_info#-readme-tab-
Output on Android emulator [see last line]:
safe_device: ^1.1.1
import 'package:safe_device/safe_device.dart';
Checks whether device is real or emulator
bool isRealDevice = await SafeDevice.isRealDevice;
(ANDROID ONLY) Check if development Options is enable on device
bool isDevelopmentModeEnable = await SafeDevice.isDevelopmentModeEnable;

Resources