EasyApp

Remove Widget and Notification Features

Remove all widget and notification features

If you temporarily don't need widget and notification features, you can follow the steps below to remove related code and configurations

Remove Widgets

  • Delete the EasyAppWidget folder, select Move to Trash

removeWidget1

  • Right-click to delete EasyAppWidgetExtension

removeWidget2

  • Uncheck widget in App Group, as shown in step 3 of the image below

removeWidget3

  • Delete the App -> Developer -> SubPages -> LiveActivity folder, select Move to Trash

removeWidget4

  • Go to App -> Developer -> View -> DeveloperView.swift file, delete the code

removeWidget5

removeWidget6

removeWidget7

removeWidget8

  • Go to EasyAppSwiftUIApp.swift file, delete the following widget related code
#if DEBUG
	@State private var showLiveActivityDemo = false
	@State private var showWidgetMicrophoneDemo = false
	@State private var showWidgetCameraDemo = false
#endif
	// live activity
	.onOpenURL { url in
			devLogger.info("onOpenURL: \(url)")
			let liveActivityValue = url.getEaspAppDeepLinkUrlParam(
					hostKey: "live-activity", name: "path")

			let widgetMicrophoneValue = url.getEaspAppDeepLinkUrlParam(
					hostKey: "microphone", name: "path")

			let widgetCameraValue = url.getEaspAppDeepLinkUrlParam(
					hostKey: "camera", name: "path")

			if let liveActivityValue, liveActivityValue == "live-activity" {
					showLiveActivityDemo.toggle()
			}

			if let widgetMicrophoneValue, widgetMicrophoneValue == "microphone" {
					showWidgetMicrophoneDemo.toggle()
			}

			if let widgetCameraValue, widgetCameraValue == "camera" {
					showWidgetCameraDemo.toggle()
			}
	}


	// widget

	.sheet(isPresented: $showWidgetMicrophoneDemo) {
			OpenWidgetMicrophoneDemo()
	}

	.sheet(isPresented: $showWidgetCameraDemo) {
			OpenWidgetCameraDemo()
	}

Remove Notification Features

  • Remove the dependency on EasyAppNotifyKit library

removeNot0

Select EasyAppNotifyKit, click the - button (might fail, try multiple times)

removeNot0_1

  • Delete notification permissions

Uncheck Notifications permission

delete-remoteN

delete-remoteN2

  • Search and delete the following imported libraries in the EasyAppSwiftUI project
 import EasyAppNotifyKit
 import OneSignalFramework
  • Delete/comment out the related code in the EasyAppSwiftUI/Lib/Auth/AuthManager.swift file
EasyAppSwiftUI/Lib/Auth/AuthManager.swift
  PushManager.shared.loginUser(userId)
EasyAppSwiftUI/Lib/Auth/AuthManager.swift
 PushManager.shared.logoutUser()
  • Delete the following content, select Move to Trash

removeNot

removeNot3

removeNot4

  • Go to EasyAppSwiftUI/App/Developer/View/DeveloperView.swift, delete the code

removeNot5

removeNot6

removeNot7

  • Uncheck removeNot2

    • Go to EasyAppSwiftUIApp.swift file, delete the following notification related code
    #if DEBUG
        	 @State private var showDeepLinkTest = false
    #endif
		// Show the deep link test view when the notification is clicked
		#if DEBUG
				.sheet(isPresented: $showDeepLinkTest) {
						OSDeepLinkTargetTestView()
				}
				.onReceive(
						NotificationCenter.default.publisher(
								for: EasyAppNotifyKit.Notifications.osNotificationClicked)
				) { notification in
						let deeplink = notification.userInfo?["deeplink"] as? String
						if let deeplink, deeplink == "EasyApp://notifykit?screen=osTests" {
								withAnimation(.spring(response: 0.5, dampingFraction: 0.8)) {
										showDeepLinkTest = true
								}
						}
				}
		#endif
	if Constants.OneSignal.isEnabledNotification {
			let oneSignalService = OneSignalService()
			PushManager.shared.configure(with: oneSignalService)

			let configuration: PushServiceConfiguration = PushServiceConfiguration(
					appId: Constants.OneSignal.appId,
					launchOptions: launchOptions
			)
			PushManager.shared.initialize(with: configuration)

			OneSignal.Notifications.addClickListener(self)
			OneSignal.Notifications.addForegroundLifecycleListener(self)
	}
extension AppDelegate: OSNotificationClickListener, OSNotificationLifecycleListener {
    func onClick(event: OSNotificationClickEvent) {
        devLogger.info("Notification clicked: \(event.jsonRepresentation())")

        self.handleViewTap(additionalData: event.notification.additionalData)
    }

    func onWillDisplay(event: OSNotificationWillDisplayEvent) {
        devLogger.info("Foreground notification: \(event.notification.title ?? "No Title")")

        event.preventDefault()

        guard let notifTitle = event.notification.title,
            let notifMessage = event.notification.body,
            let additionalData = event.notification.additionalData,
            let symbol = additionalData["symbolImage"] as? String
        else {
            event.notification.display()  // Show notification as usual
            return
        }

        var notifHaptics: UINotificationFeedbackGenerator.FeedbackType = .warning
        if let size = additionalData["status"] as? String {
            if size == "error" {
                notifHaptics = .error
            } else if size == "success" {
                notifHaptics = .success
            }

            UINotificationFeedbackGenerator().notificationOccurred(notifHaptics)
        }

        ShowNotification.showInAppNotification(
            title: notifTitle,
            message: notifMessage,
            isSuccess: notifHaptics == .success,
            duration: .seconds(seconds: 5),
            systemImage: symbol,
            handleViewTap: {
                self.handleViewTap(additionalData: event.notification.additionalData)
            }
        )

    }

    /// Handle the view tap
    /// - Parameter additionalData: the additional data
    private func handleViewTap(additionalData: [AnyHashable: Any]? = nil) {
        // Parse the additional data
        let ad = JSON(additionalData ?? [:])
        // Get the deeplink
        let deeplink = ad["deeplink"].stringValue
        if !deeplink.isEmpty {
            // Broadcast click to allow host views to react (e.g., navigate)
            NotificationCenter.default.post(
                name: EasyAppNotifyKit.Notifications.osNotificationClicked,
                object: nil,
                userInfo: [
                    "deeplink": deeplink
                ]
            )
        }
    }
}

Finally, run the Cmd + B command to check for any other errors.

Last updated on