[フレーム]
Skip to main content

Using Portals in iOS

Registering with your Portals Key

Before using Ionic Portals, you must register with your API key. A typical place to do so is in the AppDelegate application(_:didFinishLaunchingWithOptions) method. There, you can use the PortalsRegistrationManager to register:

  • Swift
  • Objective-C
funcapplication(_ application:UIApplication, didFinishLaunchingWithOptions launchOptions:[UIApplication.LaunchOptionsKey:Any]?)->Bool{
// Override point for customization after application launch.
PortalsRegistrationManager.shared.register(key:"YOUR_PORTALS_KEY")
returntrue
}

If you're integrating Ionic Portals in a pure SwiftUI application, you can register your API key in your Apps initializer:

importSwiftUI
importIonicPortals

@main
structPortalsApp:App{
init(){
PortalsRegistrationManager.shared.register(key:"YOUR_PORTALS_KEY")
}

var body:someScene{
WindowGroup{
ContentView()
}
}
}
caution

Avoid committing your Portals key to source code repositories where it may be publicly visible! On iOS, you can use an .xcconfig file to keep it out of a public repository.

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")

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
Portal Initializer
classViewController:UIViewController{
overridefuncloadView(){
let portal =Portal(name:"webapp")
self.view =PortalUIView(portal: portal)
}
}
classViewController:UIViewController{
overridefuncloadView(){
self.view =PortalUIView(portal:"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.

AltStyle によって変換されたページ (->オリジナル) /