Skip to content

issue with postNotification syntax and Swift #13

Closed

Description

@wosheesh

I've setup the app and devices successfully to receive push notifications, and tested it.

However I run into an issue while trying to use OneSignal.postNotification method. Also using your example from the API docs seems to have a mis-type issue:

OneSignal.postNotification(["contents": ["en": "Test Message"], "include_player_ids": ["3009e210-3166-11e5-bc1b-db44eb02b120"]])

generates an error: '(dictonaryLiteral: (NSObject, AnyObject), (NSObject, AnyObject))' is not convertible to '(dictionaryLiteral: (NSString, NSObject)...), tuples have a different number of elements

by the way shouldnt it be OneSignal, not oneSignal like on your API doc example?

I also tried postNotificationWithJsonString and used NSString or String as arguments just to check, and I was getting error: Cannot convert value of type 'string' to expected argument type 'OneSignal'

I suspect that I am getting something wrong with ObjC <-> Swift type, but I am not experienced enough to figure this out.

Thanks for help.

Activity

  1. wosheesh commented on Feb 22, 2016

    @wosheesh
    Author

    Looks like I was forgetting to declare let oneSignal = OneSignal() in the class. But just to be sure - is that how it should be declared each time (I still didn't get the push to work)? Or should we refer to the one declared in AppDelegate and declare it globally somehow?

  2. wosheesh commented on Feb 23, 2016

    @wosheesh
    Author

    Never mind. This is what I did in the class handling the push:

    import UIKit
    
    let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
    let oneSignal = appDelegate.oneSignal
    

    and in the AppDelegate I added var oneSignal: OneSignal? after class declaration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions