Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ios): add openInExternalBrowser #1

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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