Search code examples
iosfacebookswiftfacebook-graph-apitwitter

Post on Facebook/ twitter in background in Swift


Can anyone recommend me any swift library to post on facebook and twiiter. I am trying this for now

if FBSDKAccessToken.currentAccessToken().hasGranted("publish_actions")
    {
        print("publish actions already granted.")

    }
    else
    {
        FBSDKGraphRequest.init(graphPath: "me/feed", parameters: ["message" : "hello world"], HTTPMethod: "POST").startWithCompletionHandler({ (connection, result, error) -> Void in

            if ((error == nil))
            {
                print("Post id: \(result.valueForKey("id") as! String)")
            }
        })


    }

There is a situation that when user creates an event then my app will automatically post/tweet on its wall about the event he just created.

I am fimiliar about swifter and Facebook SDK but i am not sure if it will help me post in background


Solution

  • guys i know i asked a silly question , but after upgrading my project to swift 2.0 and fb sdk 4.6 i did the posting

    var params: NSDictionary = NSDictionary()
    let userInfo: AnyObject =  LocalStore.userDetails()!
    let name = userInfo["name"] as? String
    params = ["message": msgString]
    let request: FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "/me/feed", parameters: params as [NSObject: AnyObject], HTTPMethod: "POST")
    request.startWithCompletionHandler({ (connection, result, error) -> Void in })
    

    This way you can post any message in background... but do check for fb login and ask for publishPermission(loginWithPublishPermission).