移除小组件和通知功能
移除所有小组件和通知功能
如果暂时不需要小组件和通知功能,可以按照以下步骤来移除相关代码和配置
移除小组件
- 删除
EasyAppWidget文件夹,选择Move to Trash

- 右键删除
EasyAppWidgetExtension

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

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

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



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

#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()
}移除通知功能
- 移除
EasyAppNotifyKit这个库的依赖

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

- 删除通知权限
取消勾选通知权限


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



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



-
取消勾选

- 来到
EasyAppSwiftUI/EasyAppSwiftUIApp.swift文件,删除下面通知相关代码
- 来到
#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
]
)
}
}
}最后执行下Cmd + B命令,检查下有无其他报错。
Last updated on