EasyApp

移除小组件和通知功能

移除所有小组件和通知功能

如果暂时不需要小组件和通知功能,可以按照以下步骤来移除相关代码和配置

移除小组件

  • 删除EasyAppWidget文件夹,选择Move to Trash

removeWidget1

  • 右键删除EasyAppWidgetExtension

removeWidget2

  • 取消勾选App Group中的widget,下图 步骤 3 所示

removeWidget3

  • 删除App/Developer/SubPages/LiveActivity文件夹,选择Move to Trash

removeWidget4

  • 来到App/Developer/View/DeveloperView.swift文件,删除代码

removeWidget5

removeWidget6

removeWidget7

  • 来到EasyAppSwiftUIApp.swift文件,删除下面widget相关代码

removeWidget8

EasyAppSwiftUIApp.swift
#if DEBUG
	@State private var showLiveActivityDemo = false
	@State private var showWidgetMicrophoneDemo = false
	@State private var showWidgetCameraDemo = false
#endif
EasyAppSwiftUIApp.swift
	// 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()
	}

移除通知功能

  • 移除EasyAppNotifyKit这个库的依赖

removeNot0

选中EasyAppNotifyKit,点击-按钮,(有可能会失败,多试几次)

removeNot0_1

  • 删除通知权限

取消勾选通知权限

delete-remoteN

delete-remoteN2

  • EasyAppSwiftUI项目中搜索 以下用到的库,删除
import EasyAppNotifyKit
import OneSignalFramework
  • 删除/注释 以下 EasyAppSwiftUI/Lib/Auth/AuthManager.swift文件中的 相关代码
EasyAppSwiftUI/Lib/Auth/AuthManager.swift
  PushManager.shared.loginUser(userId)
EasyAppSwiftUI/Lib/Auth/AuthManager.swift
 PushManager.shared.logoutUser()
  • 删除以下内容, 选择Move to Trash

removeNot

removeNot3

removeNot4

  • 来到EasyAppSwiftUI/App/Developer/View/DeveloperView.swift,删除代码

removeNot5

removeNot6

removeNot7

  • 取消勾选 removeNot2

    • 来到EasyAppSwiftUI/EasyAppSwiftUIApp.swift文件,删除下面通知相关代码
EasyAppSwiftUIApp.swift
    #if DEBUG
         @State private var showDeepLinkTest = false
    #endif
EasyAppSwiftUIApp.swift
		// 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
EasyAppSwiftUIApp.swift
	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)
	}
EasyAppSwiftUIApp.swift
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
                ]
            )
        }
    }
}

最后执行下Cmd + B命令,检查下有无其他报错。

Last updated on