Mac OS X
Télécharger le SDK
Projet d’Exemple
Documentation de l’API du SDK
Lier Pushwoosh.framework
Anchor link toAjoutez 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
github "Pushwoosh/pushwoosh-mac-sdk"
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 toDans 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 toDans 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 toAjoutez le code suivant à votre AppDelegate :
import PushKitimport 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 controllerPushwoosh.sharedInstance().delegate = self
// handling push on app startPushwoosh.sharedInstance().handlePushReceived(aNotification.userInfo)
// register for push notifications!Pushwoosh.sharedInstance().registerForPushNotifications()
#import <Pushwoosh/Pushwoosh.h>
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification{ //lots of your initialization code
//-----------PUSHWOOSH PART-----------
[NSUserNotificationCenter defaultUserNotificationCenter].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 PWMessagingDelegatefunc application(_ application: NSApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { Pushwoosh.sharedInstance()?.handlePushRegistration(deviceToken)}
// system push notification registration error callback, delegate to PWMessagingDelegatefunc application(_ application: NSApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { Pushwoosh.sharedInstance()?.handlePushRegistrationFailure(error)}
// system push notification registration success callback, delegate to pushManager- (void)application:(NSApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { [[Pushwoosh sharedInstance] handlePushRegistration:deviceToken];}
// system push notification registration error callback, delegate to pushManager- (void)application:(NSApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)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 receivedfunc pushwoosh(_ pushwoosh: Pushwoosh!, onMessageReceived message: PWMessage!) { print("onMessageReceived: \(String(describing: message.payload))")}
//this event is fired when user taps the notificationfunc pushwoosh(_ pushwoosh: Pushwoosh!, onMessageOpened message: PWMessage!) { print("onMessageOpened: \(String(describing: message.payload))")}
//this event is fired when the push gets received- (void)pushwoosh:(Pushwoosh *)pushwoosh onMessageReceived:(PWMessage *)message { NSLog(@"onMessageReceived: %@", message.payload);}
//this event is fired when user taps the notification- (void)pushwoosh:(Pushwoosh *)pushwoosh onMessageOpened:(PWMessage *)message { NSLog(@"onMessageOpened: %@", message.payload);}
Activation des Notifications Push
Anchor link toAllez dans Signing and Capabilities dans votre cible. Appuyez sur + Capability et ajoutez Push Notifications.
