istornz / flutter_live_activities

A Flutter plugin to use iOS 16.1+ Live Activities ⛹️ & iPhone Dynamic Island 🏝️ features
https://dimitridessus.fr/
MIT License
160 stars 48 forks source link

areActivitiesEnabled still crashes on some devices #85

Open SeongyoungMoon opened 2 months ago

SeongyoungMoon commented 2 months ago

same issue with: https://github.com/istornz/flutter_live_activities/issues/84#issue-2332999443

This issue is because iOS under than 16.1 and Mac doesn't support the method: ActivityAuthorizationInfo().areActivitiesEnabled

So it crashes here:

public class SwiftLiveActivitiesPlugin: NSObject, FlutterPlugin, FlutterStreamHandler {
 ...
 public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
    if (call.method == "areActivitiesEnabled") {
      if #available(iOS 16.1, *) {
        result(ActivityAuthorizationInfo().areActivitiesEnabled)
      } else {
        result(false)
      }
      return
    }
    ...
    }
...
}

ActivityAuthorizationInfo().areActivitiesEnabled method doesn't show you whether the device is supported&enabled or not. It shows whether user allowed LiveActivity.

So I solved this problem adding new method:

    func isLiveActivitySupported() -> Bool {
        var isSupported = false
        if #available(iOS 16.1, *) {
            isSupported = !ProcessInfo.processInfo.isiOSAppOnMac
        }
        return isSupported
    }

I hope this way works well.

MortadhaFadhlaoui commented 1 month ago

+1

istornz commented 1 month ago

Thanks @SeongyoungMoon I will integrate your fix 👌