Search code examples
iosswiftflurry

Flurry Push Notifications in Swift


I'm using Flurry to try to send push notifications, the tutorial for all other elements of Flurry like analytics, events etc all have Swift and Obj-C however for Push its all in Obj-C.

I've got the flurry ios sdk added and everything works well because I can see my data on the flurry site.

I'm stuck at this point when it tells me to

Include FlurryMessaging.h

How do I include a .h file in Swift?

It then asks me to do the following but its not in Swift

(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

//Step1 : Call the Integration API

[FlurryMessaging setAutoIntegrationForMessaging];

//Step2 (Optional): Get a callback

[FlurryMessaging setMessagingDelegate:self];

FlurrySessionBuilder* builder = [[[FlurrySessionBuilder alloc] withIncludeBackgroundSessionsInMetrics:YES];

[Flurry startSession:@”API_KEY” withOptions:launchOptions withSessionBuilder:builder];

return YES;

}

Implement the Delegate method for Received
-(void) didReceiveMessage:(nonnull FlurryMessage*)message

{

NSLog(@”didReceiveMessage = %@”, [message description]);

//App specific implementation

}

Implement the Delegate method for Clicked
-(void) didReceiveActionWithIdentifier:(nullable NSString*)identifier message:(nonnull FlurryMessage*)message

{

NSLog(@”didReceiveAction %@ , Message = %@”,identifier, [message description]);

//Any app specific logic goes here.

//Ex: Deeplink logic (loading of viewControllers (nibs or storboards),

//additional logging, etc

}

Solution

  • If you are integrating through Cocoapods, make sure to include ‘Flurry-iOS-SDK/FlurryMessaging’in your podfile. If you have, then you can access the Messaging methods by adding this to your import statements:

    import Flurry_iOS_SDK

    Then set auto integration:

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    
    FlurryMessaging.setAutoIntegrationForMessaging()
    FlurryMessaging.setMessagingDelegate(self)
    
    //And set up your Builder:
    
    let builder = FlurrySessionBuilder.init()
    
        .withIncludeBackgroundSessionsInMetrics(true)
    
    Flurry.startSession("YOUR_API_KEY", with: builder)
    return true
    }
    

    Implement the Delegate method for Received

    func didReceive(_ message: FlurryMessage) {
        print("Did Receive Message")
        //App specific implementation
    }
    

    Implement the Delegate method for Clicked

    func didReceiveAction(withIdentifier identifier: String?, message: FlurryMessage) {
        print("Message Clicked")
        //Any app specific logic goes here.
    }