Build your Elixir application for iOS with the following mix task:
mix elixir_pack TestPackage --target iphonesimulator-arm64
Elixir Pack can build Phoenix applications to run on-device for offline support.
Add elixir_pack
as a dev dependency in your mix.exs
file.
def deps do
[
{:elixir_pack, git: "https://github.com/liveview-native/elixir_pack", branch: "main"}
]
end
Warning
Elixir Pack requires plug_crypto
v2.1.1+ to support iOS.
Specify this dependency in your mix file:
def deps do
[
{:plug_crypto, ">= 2.1.1"}
]
end
Elixir Pack will run mix release
to compile your application.
If making a production build, make sure to prepare the static files.
mix phx.digest
Run the elixir_pack
mix task to create a Swift Package containing your Phoenix server and OTP for iOS.
MIX_ENV=prod mix elixir_pack native/swiftui/YourAppServer --target iphonesimulator-arm64 --target iphoneos
Run mix help elixir_pack
to get more info on the supported options.
Open your Xcode project and add the server package as a dependency.
- Go to File -> Add Package Dependencies...
- Click the Add Local... button in the bottom left of the popup
- Select the server package generated by Elixir Pack (such as native/swiftui/YourAppServer)
- In the Add to Target dropdown, select your app's target
Import the generated package, and modify your App
struct to start the server on launch.
import YourAppServer
struct YourApp: App {
init() {
YourAppServer.start()
}
var body: some Scene {
// ...
}
}
You can optionally pass a host
, port
, and secretKeyBase
to configure the server on startup.
Ensure your LiveView
connects to the correct host and port.
struct ContentView: View {
var body: some View {
#LiveView(.localhost) // `.localhost` uses the default host and port
}
}
When you run the application, the server will start on a separate thread and the client will connect. Any logs from the server will appear in Xcode's debugger log.
If available in Hex, the package can be installed
by adding elixir_pack
to your list of dependencies in mix.exs
:
def deps do
[
{:elixir_pack, "~> 0.1.0"}
]
end
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/elixir_pack.