Recently, when the project was connected to the push, since the project was written by SWIFT and the SDK of the push was written by OC, it was inevitable to encounter the knowledge of mixed programming during the access process. Therefore, here are the notes for the access and make a record. The specific access steps are as follows:
- 1. Create
NotificationService
, the specific operation is shown in the following figure
- 2. Import the downloaded third-party library into the project, as shown in the following figure
- 3. Create a bridge file and configure a path for the bridge file
Create the bridge file swiftDemo-NotificationService- swift-Bridge-header
Configuration Items
- 4. In the created bridge file, import the name of the three-party library of the OC that will be used in the project
#import <GTExtensionSDK/GeTuiExtSdk.h>
Copy the code
- 5. Call it directly where it is needed
var contentHandler: ((UNNotificationContent) -> Void)? var bestAttemptContent: UNMutableNotificationContent? override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) { self.contentHandler = contentHandler guard let bestAttemptContent = request.content.mutableCopy() as? UNMutableNotificationContent else {return} / / / GTSDK statistical APNs arrival, and multimedia push support interface, It is recommended to use this interface GeTuiExtSdk. HandelNotificationServiceRequest (request, withAttachmentsComplete: {[weak self] (attachments: Array? , errors: Array?) in guard let handler = self? ContentHandler else {return} // [test code] TODO: printout (" printout "); \(String(describing: Errors))") // TODO: This is where the user can handle changes to the notification style, eg: changing the title, Bestattemptcontent.title = "\(beStatTemptContent.title) [Success]" if let attachment = attachments as? [UNNotificationAttachment], ! Attachment. IsEmpty {/ / set up notifications of multimedia attachment bestAttemptContent. Attachments = attachment} / show/push callback processing needs to be done on a push receipt in the callback handler(bestAttemptContent) }) }Copy the code