Using Portals in iOS
Creating a Portal
- Swift
- Objective-C
Create a Portal via it's initializer:
let portal = Portal(name: "webapp")
Portal also conforms to ExpressibleByStringLiteral:
let portal: Portal = "webapp"
By default, a Portal will use the name property as the directory to load web content from (relative to the root of Bundle.main). You can specify another location if needed:
let portal = Portal(name: "webapp", startDir: "portals/webapp")
Create an IONPortal via it's initializer:
IONPortal *portal = [[IONPortal alloc] initWithName:@"webapp", startDir:nil, initialContext:nil];
By default, IONPortal will use the name provided in the initializer if startDir is nil.
Using PortalView and PortalUIView
After you initialize a Portal, you create a PortalView (for SwiftUI) or PortalUIView (for UIKit) by passing in the Portal.
- UIKit (Swift)
- UIKit (Objective-C)
- SwiftUI
class ViewController: UIViewController {
override func loadView() {
let portal = Portal(name: "webapp")
self.view = PortalUIView(portal: portal)
}
}
class ViewController: UIViewController {
override func loadView() {
self.view = PortalUIView(portal: "webapp")
}
}
@implementation ViewController
- (void)loadView {
IONPortal *portal = [[IONPortal alloc] initWithName:@"webapp" startDir:nil initialContext:nil];
self.view = [[IONPortalUIView alloc] initWithPortal:portal];
}
@end
struct ContentView: View {
var body: some View {
VStack {
// Using ExpressibleByStringLiteral conformance
PortalView(portal: "webapp")
PortalView(portal: .init(name: "webapp", startDir: "portals/webapp"))
}
}
}
Adding Web Code
Now that your Portal is successfully created and added to the view, you need to add the web assets to your application. In iOS, the web folder needs to be copied and added to the XCode project. After the folder is added, you can update its contents with fresh builds of the web application. For more information on how to set up your web bundle, see our how-to guide on how to pull in a web bundle.