-
-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to open flutter carplay with proper data without opening app? #56
Comments
Hi, @richanshah. I managed to find the solution to this issue with the comment at this link #12 (comment) -1150229720 |
OK, Thanks I will give it a try. |
@richanshah did you have any luck with the solution in the link provided? I was not able to get it working. |
@derrik-fleming The main idea is to move the FlutterEngine creation to the AppDelegate, which will be run when the app is launched from anywhere (CarPlay or device). We can run the FlutterEngine in headless mode, so the dart code can run before the engine is attached to any actual view (which happens when launching the app first on the CarPlay). Then, on the SceneDelegate we reuse the engine and attach it to the actual view. So the AppDelegate.swift will be like this: import UIKit let flutterEngine = FlutterEngine(name: "SharedEngine", project: nil, allowHeadlessExecution: true) @UIApplicationMain
} @available(iOS 13.0, *)
} func templateApplicationScene(_ templateApplicationScene: CPTemplateApplicationScene,
} |
I tried above code but it is not working for me. |
@viniciusoliverrs I was able to get it working. But I have a question about something that doesn't seem to be working in the same way as it does when the app is launched from the mobile device. Do you know how I could get an accurate value for |
I'm trying to use FlutterCarplay.connectionStatus to retrieve the CarPlay connection status for fetching data when CarPlay opens without the app running. However, the status is not being returned consistently, which is causing some issues. If you know of any workarounds or have suggestions on how to get a reliable connection status in this scenario, please let me know. Thank you! |
@richanshah did you manage to solve the issue when Carplay opens without opening app? i tried above solution but does not work, it shows blank screen when opens directly from carPlay. |
@harpreetslabs Ensure the app is not still running on CarPlay in the background. Try uninstalling the app first before testing the above code if you have not already. Or open it on the mobile device first, then close (which will close the app on CarPlay), and then try opening it on the CarPlay device. It seems like if the app is running on CarPlay in the background you may continue to have a blank screen. |
Yes, my question is how I can work by opening the app from carplay directly, instead of opening the flutter app first. |
@derrik-fleming I noticed one thing, when we open directly from carplay it shows black screen, then on closing carplay and opening again works fine. (I have not opened the Flutter app yet). |
no, I have still the same issue as yours.
|
Any workaround for this? |
@harpreetslabs Are you using the connection events to determine if you should push templates on to CarPlay? The thing that I noticed with the solution in this thread is that when launching the app from CarPlay (without opening the mobile app) is that the connection status is never updated, so it remains in its initialized value ( |
I also facing same thing. I am trying different ways but nothing works yet
…On Thu, Nov 7, 2024, 7:22 PM derrik-fleming ***@***.***> wrote:
@derrik-fleming <https://github.com/derrik-fleming> I noticed one thing,
when we open directly from carplay it shows black screen, then on closing
carplay and opening again works fine. (I have not opened the Flutter app
yet).
Are you using the connection events to determine if you should push
templates on to CarPlay? The thing that I noticed with the solution in this
thread is that when launching the app from CarPlay (without opening the
mobile app) is that the connection status is never updated, so it remains
in its initialized value (unknown) until another event occurs.
—
Reply to this email directly, view it on GitHub
<#56 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEA54E535H6IU2ICVYTRXJ3Z7NWBHAVCNFSM6AAAAABQDOOD5WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINRSGI4TGNRVGI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@richanshah @derrik-fleming you can try this fork: |
That's neat. I think all of the apps included with iOS behave in that same manner. So, I'm not sure that I would consider that an issue, unless you want it to perform otherwise. |
thanks but I don't want to kill carplay on killing the app. |
if you see Spotify or Youtube music it does not work that day. |
https://stackoverflow.com/a/78546045/9248248 this works for me but the issue is I have lots of data for carplay so it takes more time in the app so it cause performance issue. |
I have a same issue, thanks @viniciusoliverrs this works on debug/release mode, but crash the app on testflight build. Any suggestions? |
Can you explain better? |
//Firstly you can set an emtpy template for init
FlutterCarplay.setRootTemplate(
rootTemplate: CPTabBarTemplate(
templates: [
TabPage1().get(),
TabPage2().get(),
TabPage3().get(),
],
),
animated: true,
);
carplay.forceUpdateRootTemplate();
// TabPage singleton
class TabPage1 {
static final TabPage1 _singleton = TabPage1._internal();
CPListTemplate? template;
List<CPListSection> sections = [];
factory TabPage1() {
return _singleton;
}
CPListTemplate get() {
final template = CPListTemplate(
sections: sections,
title: "Title",
emptyViewTitleVariants: [],
systemIcon: "icon"
);
this.template = template;
return template;
}
//call it when templateWillAppear
Future<void> refresh() async {
if (sections.isNotEmpty) return;
// fetch api data and setup list sections
template?.udpate(sections);
}
} e.g: FCPListTemplate update |
I followed the necessary steps, and everything works fine in both debug and release modes. However, the app crashes only when building on TestFlight. The crash report points to CarPlay. Updating CarPlay was the only change since the last successful TestFlight build. Exception Type: EXC_BAD_ACCESS (SIGSEGV) static SwiftFlutterCarplayPlugin.register(with:) + 120 (SwiftFlutterCarplayPlugin.swift:31) Has anyone experienced a similar issue or have any ideas about what could be causing this? |
Have you solved this issue? I could not get the correct status if CarPlay was already open and then the app was opened. |
I tried to check using native code and added method channels. It works for me, but can you please check if it works fine? Here is the implementation: import UIKit
import Flutter
let flutterEngine = FlutterEngine(name: "SharedEngine", project: nil, allowHeadlessExecution: true)
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
flutterEngine.run()
GeneratedPluginRegistrant.register(with: flutterEngine)
let methodChannel = FlutterMethodChannel(
name: "carplay_status_channel",
binaryMessenger: flutterEngine.binaryMessenger
)
methodChannel.setMethodCallHandler { (call, result) in
if call.method == "isCarPlayConnected" {
result(self.isCarPlayConnected())
} else {
result(FlutterMethodNotImplemented)
}
}
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
private func isCarPlayConnected() -> Bool {
for screen in UIScreen.screens {
if screen.traitCollection.userInterfaceIdiom == .carPlay {
return true
}
}
return false
}
} |
ok thanks @harpreetslabs will update u |
@derrik-fleming @richanshah Does your app open correctly? I am experiencing an issue where, when I open the app, it first shows the previous state, then displays the splash screen, and finally starts the app. Screen.Recording.2024-11-25.at.1.04.15.PM.online-video-cutter.com.mp4 |
@harpreetslabs it works fine for me. |
no there is no direct way to get this. I am looking into this. |
|
official one. |
Try using the fork https://github.com/brasilflutter/flutter_carplay |
Does this fork solve the issue when carplay opened without app opening? |
Steps to reproduce
Open app in carplay and mobile device both
Play any song from carplay
Kill the app from mobile and observe that carplay app also stopped
Now open the app in carplay only
Observe
You will see "Please wait while data fetching" on collections, playlists and songs screen when you kill the app and then open app in carplay
Also this happens when you close the app and go back into the app in carplay only then click music you just get spinning.
[✓] Flutter (Channel stable, 3.19.5, on macOS 14.2.1 23C71 darwin-arm64 (Rosetta), locale en-IN)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.0)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.1)
The text was updated successfully, but these errors were encountered: