Skip to content
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
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let package = Package(
targets: ["NativeSettingsPlugin"])
],
dependencies: [
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.2")
],
targets: [
.target(
Expand Down
22 changes: 6 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Provides access to native Android and iOS system settings screens.
### open(...)

```typescript
open(options: PlatformOptions) => Promise<NativeSettingsResult>
open(options: PlatformOptions) => Promise<{ status: boolean; }>
```

Opens the specified settings option on the current platform.
Expand All @@ -96,15 +96,15 @@ Opens the specified settings option on the current platform.
| ------------- | ----------------------------------------------------------- | ----------------------------------- |
| **`options`** | <code><a href="#platformoptions">PlatformOptions</a></code> | Platform-specific settings options. |

**Returns:** <code>Promise&lt;<a href="#nativesettingsresult">NativeSettingsResult</a>&gt;</code>
**Returns:** <code>Promise&lt;{ status: boolean; }&gt;</code>

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


### openAndroid(...)

```typescript
openAndroid(options: AndroidOptions) => Promise<NativeSettingsResult>
openAndroid(options: AndroidOptions) => Promise<{ status: boolean; }>
```

Opens the specified Android settings screen.
Expand All @@ -113,15 +113,15 @@ Opens the specified Android settings screen.
| ------------- | --------------------------------------------------------- | ------------------------- |
| **`options`** | <code><a href="#androidoptions">AndroidOptions</a></code> | Android settings options. |

**Returns:** <code>Promise&lt;<a href="#nativesettingsresult">NativeSettingsResult</a>&gt;</code>
**Returns:** <code>Promise&lt;{ status: boolean; }&gt;</code>

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


### openIOS(...)

```typescript
openIOS(options: IOSOptions) => Promise<NativeSettingsResult>
openIOS(options: IOSOptions) => Promise<{ status: boolean; }>
```

Opens the specified iOS settings screen.
Expand All @@ -130,24 +130,14 @@ Opens the specified iOS settings screen.
| ------------- | ------------------------------------------------- | --------------------- |
| **`options`** | <code><a href="#iosoptions">IOSOptions</a></code> | iOS settings options. |

**Returns:** <code>Promise&lt;<a href="#nativesettingsresult">NativeSettingsResult</a>&gt;</code>
**Returns:** <code>Promise&lt;{ status: boolean; }&gt;</code>

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


### Interfaces


#### NativeSettingsResult

Result returned by native settings operations.

| Prop | Type | Description |
| ------------- | -------------------- | ----------------------------------------------- |
| **`success`** | <code>boolean</code> | Indicates whether the operation succeeded. |
| **`error`** | <code>string</code> | Optional error message if the operation failed. |


#### PlatformOptions

Platform-specific options.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ public void openAndroid(PluginCall call) {

private void openInternal(PluginCall call, String option) {
if (option == null) {
resolveError(call, "Missing option parameter");
call.reject("Missing option parameter");
return;
}

String setting = AndroidSettings.getAction(option);
if (setting == null) {
resolveError(call, "Unsupported Android setting: " + option);
call.reject("Unsupported Android setting: " + option);
return;
}

Expand Down Expand Up @@ -83,11 +83,4 @@ private void activityResult(PluginCall call, ActivityResult result) {
response.put("success", true);
call.resolve(response);
}

private void resolveError(PluginCall call, String message) {
JSObject response = new JSObject();
response.put("success", false);
response.put("error", message);
call.resolve(response);
}
}
9 changes: 3 additions & 6 deletions ios/Sources/NativeSettingsPlugin/NativeSettingsPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public class NativeSettingsPlugin: CAPPlugin, CAPBridgedPlugin {

/// Opens a system settings page (legacy key).
@objc func open(_ call: CAPPluginCall) {
let option = call.getString("optionIOS", "")
let option = call.getString("optionIOS") ?? ""
handleOpen(call: call, option: option)
}

/// Opens a system settings page.
@objc func openIOS(_ call: CAPPluginCall) {
let option = call.getString("option", "")
let option = call.getString("option") ?? ""
handleOpen(call: call, option: option)
}

Expand All @@ -41,10 +41,7 @@ public class NativeSettingsPlugin: CAPPlugin, CAPBridgedPlugin {
guard let url = implementation.resolveSettingsURL(for: option),
UIApplication.shared.canOpenURL(url) else {
log("Invalid or unsupported option:", option)
call.resolve([
"success": false,
"error": "Requested setting '\(option)' is not available on iOS."
])
call.reject("Requested setting '\(option)' is not available on iOS.")
return
}

Expand Down
Loading
Loading