Passer au contenu

Mac OS X

Télécharger le SDK
Projet d’Exemple
Documentation de l’API du SDK

Lier Pushwoosh.framework

Anchor link to

Ajoutez Pushwoosh.framework à votre projet via un gestionnaire de dépendances en ajoutant les lignes suivantes dans votre podfile ou cartfile :

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

Alternativement, vous pouvez simplement glisser-déposer le framework dans Link Binaries With Libraries dans les Build Phases de votre projet.

Ajout de bibliothèques

Anchor link to

Dans l’onglet Build Phases de votre projet, ouvrez Link Binaries With Libraries et cliquez sur Ajouter des éléments (bouton « + »). Recherchez et ajoutez les bibliothèques libz.tbd et libc++.tbd à votre projet :

Lier l’application avec le Panneau de Contrôle Pushwoosh

Anchor link to

Dans votre Info.plist, ajoutez une clé de type chaîne de caractères Pushwoosh_APPID avec votre Code d’Application Pushwoosh comme valeur.

Modification de l’AppDelegate

Anchor link to

Ajoutez le code suivant à votre AppDelegate :

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()

Ajoutez le code suivant à votre UIApplicationDelegate (même fichier que ci-dessus).

// 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)
}

Pour gérer les notifications push, ajoutez la fonction suivante à votre UIApplicationDelegate (le même fichier que les trois étapes précédentes) :

//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))")
}

Activation des Notifications Push

Anchor link to

Allez dans Signing and Capabilities dans votre cible. Appuyez sur + Capability et ajoutez Push Notifications.