diff --git a/example/ios/App/App/Info.plist b/example/ios/App/App/Info.plist
index 35920e1..9c5c39e 100644
--- a/example/ios/App/App/Info.plist
+++ b/example/ios/App/App/Info.plist
@@ -88,6 +88,26 @@
ionic-icon
+ ionitron-icon
+
+ UIPrerenderedIcon
+
+ CFBundleIconFiles
+
+
+ ionitron-icon
+
+
+ stencil-icon
+
+ UIPrerenderedIcon
+
+ CFBundleIconFiles
+
+
+ stencil-icon
+
+
diff --git a/example/src/components/app-home/app-home.tsx b/example/src/components/app-home/app-home.tsx
index ecdd4aa..12f5cc3 100644
--- a/example/src/components/app-home/app-home.tsx
+++ b/example/src/components/app-home/app-home.tsx
@@ -11,7 +11,7 @@ export class AppHome {
async resetIcon() {
try {
- await AppIcon.reset()
+ await AppIcon.reset({suppressNotification: true})
} catch (error) {
console.debug(error)
}
@@ -27,10 +27,11 @@ export class AppHome {
let setIconName = await AppIcon.getName();
console.debug(`App Icon set to: `,setIconName.value);
- await AppIcon.change({name: iconName});
+ await AppIcon.change({name: iconName, suppressNotification: true});
setIconName = await AppIcon.getName();
console.debug(`App Icon set to: `,setIconName.value);
+
} catch (error) {
console.debug(error)
}
diff --git a/ios/Plugin/Plugin.swift b/ios/Plugin/Plugin.swift
index 102d6bd..46a1bbe 100644
--- a/ios/Plugin/Plugin.swift
+++ b/ios/Plugin/Plugin.swift
@@ -21,48 +21,51 @@ public class AppIcon: CAPPlugin {
}
@objc func reset(_ call: CAPPluginCall) {
- changeIcon(iconName: nil, call)
+ let suppressNotification = call.getBool("suppressNotification") ?? true
+
+ setIcon(iconName: nil, suppressNotification: suppressNotification, call)
}
@objc func change(_ call: CAPPluginCall) {
- CAPLog.print("Changing app icon.")
guard let iconName = call.getString("name") else {
call.reject("Must provide an icon name.")
return
}
- DispatchQueue.main.sync {
-
- if UIApplication.shared.responds(to: #selector(getter: UIApplication.supportsAlternateIcons)) && UIApplication.shared.supportsAlternateIcons {
- typealias setAlternateIconName = @convention(c) (NSObject, Selector, NSString?, @escaping (NSError) -> ()) -> ()
-
- let selectorString = "_setAlternateIconName:completionHandler:"
-
- let selector = NSSelectorFromString(selectorString)
- let imp = UIApplication.shared.method(for: selector)
- let method = unsafeBitCast(imp, to: setAlternateIconName.self)
- method(UIApplication.shared, selector, iconName as NSString?, { _ in })
-
- call.resolve();
- }
- }
+ let suppressNotification = call.getBool("suppressNotification") ?? true
+
+ setIcon(iconName: iconName, suppressNotification: suppressNotification, call)
}
- func changeIcon(iconName: String?, _ call: CAPPluginCall) {
+ func setIcon(iconName: String?, suppressNotification: Bool, _ call: CAPPluginCall) {
DispatchQueue.main.sync {
// Check if the app supports alternating icons
guard UIApplication.shared.supportsAlternateIcons else {
return call.reject("Alternate icons not supported.");
}
+
+ if(suppressNotification) {
+ if UIApplication.shared.responds(to: #selector(getter: UIApplication.supportsAlternateIcons)) && UIApplication.shared.supportsAlternateIcons {
+ typealias setAlternateIconName = @convention(c) (NSObject, Selector, NSString?, @escaping (NSError) -> ()) -> ()
+
+ let selectorString = "_setAlternateIconName:completionHandler:"
+
+ let selector = NSSelectorFromString(selectorString)
+ let imp = UIApplication.shared.method(for: selector)
+ let method = unsafeBitCast(imp, to: setAlternateIconName.self)
+ method(UIApplication.shared, selector, iconName as NSString?, { _ in })
+
+ call.resolve();
+ }
- // Change the icon to a specific image with given name
- UIApplication.shared.setAlternateIconName(iconName) { (error) in
- // After app icon changed, print our error or success message
- if let error = error {
- call.reject("App icon failed to due to \(error.localizedDescription)")
- } else {
- call.resolve()
+ } else {
+ UIApplication.shared.setAlternateIconName(iconName) { (error) in
+ if let error = error {
+ call.reject("App icon failed to due to \(error.localizedDescription)")
+ } else {
+ call.resolve()
+ }
}
}
}
diff --git a/package.json b/package.json
index 4f90cc0..d9c4cd1 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "@capacitor-community/app-icon",
- "version": "0.0.1",
+ "version": "0.3.0",
"description": "Capacitor community plugin for changing an iOS app icon.",
"main": "dist/plugin.js",
"module": "dist/esm/index.js",
diff --git a/src/definitions.ts b/src/definitions.ts
index 080c020..68e3746 100644
--- a/src/definitions.ts
+++ b/src/definitions.ts
@@ -5,27 +5,37 @@ declare module '@capacitor/core' {
}
interface IconOptions {
+ /**
+ * Name of alternate icon to set
+ */
name: string;
+ /**
+ * Flag controlling the in app notification which shows after icon is changed.
+ */
suppressNotification: boolean
}
export interface AppIconPlugin {
/**
* Checks if changing the app icon is supported
+ * @since 1.0.0
*/
isSupported(): Promise<{value: boolean}>;
/**
* Gets the name of currently set alternate icon. If original icon is set, returns null.
+ * @since 1.0.0
*/
getName(): Promise<{value: string | null}>;
/**
* Changes app icon to specified alternate.
+ * @since 1.0.0
*/
change(options: IconOptions): Promise;
/**
* Reverts app icon to original.
- * */
- reset(suppressNotification: boolean): Promise;
+ * @since 1.0.0
+ */
+ reset(options: {suppressNotification: boolean}): Promise;
// appIconBadgeNumber(): Promise<{value: number}>;
}
\ No newline at end of file