Skip to content

Commit

Permalink
feat(ios): add openInExternalBrowser (#1)
Browse files Browse the repository at this point in the history
This includes an adapter between OSIABRouter and UIApplication to perform the url open and a model containing the url to be consumed.
Create a OpenInExternalBrowserParameterModel type with the method's parameters.
Add the xcframework to the podspec file.

References: https://outsystemsrd.atlassian.net/browse/RMET-3421
  • Loading branch information
OS-ricardomoreirasilva authored May 29, 2024
1 parent c72fa27 commit 17a7c59
Show file tree
Hide file tree
Showing 36 changed files with 1,885 additions and 24 deletions.
4 changes: 3 additions & 1 deletion CapacitorOsInappbrowser.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ Pod::Spec.new do |s|
s.homepage = package['repository']['url']
s.author = package['author']
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
#s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
s.source_files = 'ios/Sources/InAppBrowserPlugin/*.{swift,h,m,c,cc,mm,cpp}'
s.vendored_frameworks = 'ios/Sources/InAppBrowserPlugin/OSInAppBrowserLib.xcframework'
s.ios.deployment_target = '13.0'
s.dependency 'Capacitor'
s.swift_version = '5.1'
Expand Down
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ npx cap sync
* [`removeAllListeners()`](#removealllisteners)
* [`addListener('browserClosed' | 'browserPageLoaded', ...)`](#addlistenerbrowserclosed--browserpageloaded-)
* [Interfaces](#interfaces)
* [Type Aliases](#type-aliases)
* [Enums](#enums)

</docgen-index>
Expand Down Expand Up @@ -58,12 +59,12 @@ openInSystemBrowser(url: string, options: SystemBrowserOptions) => void
### openInExternalBrowser(...)

```typescript
openInExternalBrowser(url: string) => void
openInExternalBrowser(model: OpenInExternalBrowserParameterModel) => void
```

| Param | Type |
| --------- | ------------------- |
| **`url`** | <code>string</code> |
| Param | Type |
| ----------- | --------------------------------------------------------------------------------------------------- |
| **`model`** | <code><a href="#openinexternalbrowserparametermodel">OpenInExternalBrowserParameterModel</a></code> |

--------------------

Expand Down Expand Up @@ -187,6 +188,16 @@ addListener(eventName: 'browserClosed' | 'browserPageLoaded', listenerFunc: () =
| **`remove`** | <code>() =&gt; Promise&lt;void&gt;</code> |


### Type Aliases


#### OpenInExternalBrowserParameterModel

Defines the options for opening a URL in the external browser.

<code>{ url: string; }</code>


### Enums


Expand Down
5 changes: 3 additions & 2 deletions example-app/src/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import './Home.css';
const Home: React.FC = () => {

const test = () => {
// InAppBrowser.openInExternalBrowser('https://www.google.com');
console.log('test')
InAppBrowser.openInExternalBrowser({
url: "https://www.google.com"
});
}

return (
Expand Down
8 changes: 0 additions & 8 deletions ios/Sources/InAppBrowserPlugin/InAppBrowser.swift

This file was deleted.

35 changes: 27 additions & 8 deletions ios/Sources/InAppBrowserPlugin/InAppBrowserPlugin.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Foundation
import Capacitor
import OSInAppBrowserLib
import UIKit

/**
* Please read the Capacitor iOS Plugin Development Guide
Expand All @@ -10,14 +11,32 @@ public class InAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
public let identifier = "InAppBrowserPlugin"
public let jsName = "InAppBrowser"
public let pluginMethods: [CAPPluginMethod] = [
CAPPluginMethod(name: "echo", returnType: CAPPluginReturnPromise)
CAPPluginMethod(name: "openInExternalBrowser", returnType: CAPPluginReturnPromise)
]
private let implementation = InAppBrowser()

@objc func echo(_ call: CAPPluginCall) {
let value = call.getString("value") ?? ""
call.resolve([
"value": implementation.echo(value)
])
private var plugin: OSIABEngine?

override public func load() {
self.plugin = .init(application: .shared)
}

@objc func openInExternalBrowser(_ call: CAPPluginCall) {
if self.plugin == nil {
self.load()
}

guard let plugin else {
return call.reject("Capacitor bridge is not initialized.")
}

guard let url = call.getString("url") else {
return call.reject("The input parameters for 'openInExternalBrowser' are invalid.")
}

if plugin.openExternalBrowser(url) == true {
call.resolve()
} else {
call.reject("Couldn't open '\(url)' using Safari.")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AvailableLibraries</key>
<array>
<dict>
<key>BinaryPath</key>
<string>OSInAppBrowserLib.framework/OSInAppBrowserLib</string>
<key>DebugSymbolsPath</key>
<string>dSYMs</string>
<key>LibraryIdentifier</key>
<string>ios-arm64</string>
<key>LibraryPath</key>
<string>OSInAppBrowserLib.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
</dict>
<dict>
<key>BinaryPath</key>
<string>OSInAppBrowserLib.framework/OSInAppBrowserLib</string>
<key>DebugSymbolsPath</key>
<string>dSYMs</string>
<key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>OSInAppBrowserLib.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
</array>
<key>CFBundlePackageType</key>
<string>XFWK</string>
<key>XCFrameworkFormatVersion</key>
<string>1.0</string>
</dict>
</plist>
Loading

0 comments on commit 17a7c59

Please sign in to comment.