Zum Inhalt springen

macOS

SDK herunterladen
Beispielprojekt
SDK-API-Dokumentation

Bevor Sie das SDK integrieren, konfigurieren Sie die macOS-Plattform in Ihrem Pushwoosh-Projekt. Folgen Sie der Anleitung zur macOS-Konfiguration.

Verknüpfen des Pushwoosh.framework

Anchor link to

Fügen Sie das Pushwoosh.framework über einen Abhängigkeitsmanager zu Ihrem Projekt hinzu, indem Sie die folgenden Zeilen in Ihre podfile oder cartfile einfügen:

platform :osx, '10.7'
target 'MyApp' do
pod 'Pushwoosh_mac'
end

Alternativ können Sie das Framework einfach per Drag & Drop in Link Binaries With Libraries in den Build Phases Ihres Projekts ziehen.

Hinzufügen von Bibliotheken

Anchor link to

Öffnen Sie im Tab Build Phases Ihres Projekts Link Binaries With Libraries und klicken Sie auf „Elemente hinzufügen“ („+“-Button). Suchen Sie nach den Bibliotheken libz.tbd und libc++.tbd und fügen Sie sie Ihrem Projekt hinzu:

Verknüpfen der App mit dem Pushwoosh Control Panel

Anchor link to

Fügen Sie in Ihrer Info.plist einen Schlüssel vom Typ String Pushwoosh_APPID mit Ihrem Pushwoosh Application Code als Wert hinzu.

Ändern des AppDelegate

Anchor link to

Fügen Sie den folgenden Code zu Ihrem AppDelegate hinzu:

import PushKit
import Pushwoosh
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
//lots of your initialization code
//-----------PUSHWOOSH PART-----------
NSUserNotificationCenter.default.delegate = Pushwoosh.sharedInstance()?.notificationCenterDelegateProxy
// set custom delegate for push handling, in our case - view controller
Pushwoosh.sharedInstance().delegate = self
// handling push on app start
Pushwoosh.sharedInstance().handlePushReceived(aNotification.userInfo)
// register for push notifications!
Pushwoosh.sharedInstance().registerForPushNotifications()

Fügen Sie den folgenden Code zu Ihrem UIApplicationDelegate hinzu (dieselbe Datei wie oben).

// system push notification registration success callback, delegate to PWMessagingDelegate
func application(_ application: NSApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Pushwoosh.sharedInstance()?.handlePushRegistration(deviceToken)
}
// system push notification registration error callback, delegate to PWMessagingDelegate
func application(_ application: NSApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
Pushwoosh.sharedInstance()?.handlePushRegistrationFailure(error)
}

Um Push-Benachrichtigungen zu verarbeiten, fügen Sie die folgende Funktion zu Ihrem UIApplicationDelegate hinzu (dieselbe Datei wie drei Schritte zuvor):

//this event is fired when the push gets received
func pushwoosh(_ pushwoosh: Pushwoosh!, onMessageReceived message: PWMessage!) {
print("onMessageReceived: \(String(describing: message.payload))")
}
//this event is fired when user taps the notification
func pushwoosh(_ pushwoosh: Pushwoosh!, onMessageOpened message: PWMessage!) {
print("onMessageOpened: \(String(describing: message.payload))")
}

Aktivieren von Push-Benachrichtigungen

Anchor link to

Gehen Sie zu Signing and Capabilities in Ihrem Target. Drücken Sie + Capability und fügen Sie Push Notifications hinzu.