DLLocalNotifications 开源项目教程
1. 项目的目录结构及介绍
DLLocalNotifications 项目的目录结构如下:
DLLocalNotifications/
├── Assets/
├── DLLocalNotifications.xcodeproj/
├── DLLocalNotifications/
├── DLLocalNotificationsHost/
├── DLLocalNotificationsHostUITests/
├── DLLocalNotificationsTests/
├── .gitignore
├── .swift-version
├── .travis.yml
├── DLLocalNotifications.podspec
├── LICENSE
└── README.md
目录介绍:
- Assets/: 存放项目资源文件。
- DLLocalNotifications.xcodeproj/: Xcode 项目文件。
- DLLocalNotifications/: 项目的主要代码文件。
- DLLocalNotificationsHost/: 项目的主机应用。
- DLLocalNotificationsHostUITests/: 主机应用的 UI 测试。
- DLLocalNotificationsTests/: 项目的单元测试。
- .gitignore: Git 忽略文件配置。
- .swift-version: Swift 版本配置。
- .travis.yml: Travis CI 配置文件。
- DLLocalNotifications.podspec: CocoaPods 配置文件。
- LICENSE: 项目许可证。
- README.md: 项目说明文档。
2. 项目的启动文件介绍
项目的启动文件位于 DLLocalNotifications/DLLocalNotifications.swift
。这个文件包含了项目的核心逻辑和初始化代码。
import Foundation
import UserNotifications
import MapKit
let MAX_ALLOWED_NOTIFICATIONS = 64
@available(iOS 10.0, *)
public class DLNotificationScheduler {
static let maximumScheduledNotifications = 60
public init() {}
public func cancelAllNotifications() {
UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
DLQueue.queue.clear()
DLQueue.saveQueue()
}
public func cancelNotification(notification: DLNotification) {
notification.cancel()
}
public func printAllNotifications() {
UNUserNotificationCenter.current().getPendingNotificationRequests(completionHandler: { requests in
for request in requests {
print(request)
}
})
}
}
3. 项目的配置文件介绍
CocoaPods 配置文件 (DLLocalNotifications.podspec
)
Pod::Spec.new do |spec|
spec.name = 'DLLocalNotifications'
spec.version = '1.0.0'
spec.license = { :type => 'MIT' }
spec.homepage = 'https://github.com/d7laungani/DLLocalNotifications'
spec.authors = { 'Devesh Laungani' => 'devesh@laungani.com' }
spec.summary = 'Easily create Local Notifications in swift'
spec.source = { :git => 'https://github.com/d7laungani/DLLocalNotifications.git', :tag => '1.0.0' }
spec.source_files = 'DLLocalNotifications/*.swift'
spec.platform = :ios, '10.0'
spec.swift_version = '5.0'
end
Travis CI 配置文件 (.travis.yml
)
language: objective-c
osx_image: xcode11.3
script:
- xcodebuild test -project DLLocalNotifications.xcodeproj -scheme DLLocalNotifications -destination 'platform=iOS Simulator,name=iPhone 11,OS=13.2'
Swift 版本配置文件 (.swift-version
)
5.0
Git 忽略文件配置 (.gitignore
)
# Xcode
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
# CocoaPods
Pods/
Podfile.lock
以上是 DLLocalNotifications 开源项目的目录结构、启动文件和配置文件的详细介绍。希望这份文档能帮助你更好地