PiKaPiKa
PiKaPiKa

Reputation: 21

How to implement home screen widget for iOS app with multiple schemes for different apps?

I have a flutter app with two flavors and I want to add home screen widget for iOS deployment for only one flavor of app.

Each flavor of my app is corresponding to a unique bundle ID (my.domain.app1 and my.domain.app2).

I set scheme in Xcode following flutter tutorial.

I created home screen widget in iOS using this tutorial.

I give bundle ID for my home screen widget my.domain.app2.homeWidget as I want home widget for only app2. I do not need home widget for app1.

I try running app2 and it has no issue.
However, I try debugging my app1, it causes this error.
Embedded binary's bundle identifier is not prefixed with the parent app's bundle identifier

I tried removing homeWidget from Build Phases > Embed Foundation Extensions but it removes my home widget from both app1 and app2. I cannot keep home widget for only one app scheme.

How can I assign home widget in iOS to only my.domain.app2 but not my.domain.app1?

Upvotes: 1

Views: 507

Answers (1)

Rakan Alotibi
Rakan Alotibi

Reputation: 1

Simply You need 'Active Compilation Conditions' for each Environment.

Steps:

  1. Add 'Active Compilation Conditions':
  1. Use your 'Active Compilation Conditions' to decide whether to include a Widget or not:

@main
struct WidgetTestBundle: WidgetBundle {
    var body: some Widget {
        #if PROD
        WidgetTest()
        #endif
    }
}

Done 🫡

Additional: For Embedded binary's bundle identifier is not prefixed with the parent app's bundle identifier that you mentioned

The solution is:

1- Select your widget target

2- For every scheme prod/dev/stg change their bundle identifier to match your app bundle identifier for every flavor + ".widgetName" for example:

You have two flavors dev and prod

Your app bundle ID in prod flavor is com.example.AppName your widget bundle ID in this scheme should be com.example.AppName.WidgetName

And For the second flavor:

Your app bundle ID in dve flavor is com.example.AppName.dev your widget bundle ID in this scheme should be com.example.AppName.dev.WidgetName

I hope that was useful ☺️

Upvotes: 0

Related Questions