Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know if user shared my app or not?

My app is all about getting points and winning money, and what I need to do is let the user share my app then give him some points.

The problem is that I don't know how to detect if the user truly shared the app or not

I'm using the following code:

func shareTapped(){
    let text = "example"
    let url = URL(string: "example.com")
    let image = UIImage(named: "example_image")
    let shareViewController = UIActivityViewController(activityItems: [text, image!, url!] ,applicationActivities: nil)
    self.present(shareViewController, animated: true, completion: {() in
        print("done")
    })
}

The sharing method is working perfectly, but I was wondering if there is any delegate we can call in this situation.

Thanks.

like image 612
Abdulrahman Alhayek Avatar asked Feb 23 '19 12:02

Abdulrahman Alhayek


1 Answers

So there is 2 scenarios where user can cancel share.

One is when UIActivityViewController present then there is a cancel button on UIActivityViewController from where user can cancel it and yes you can detect it with method

shareViewController.completionWithItemsHandler = { activity, completed, items, error in

}

In above method completed will be false if user canceled from UIActivityViewController cancel button. and it will return true if user share successfully but here comes second case with it.

So for second case suppose user want to share via watsapp and click on watsapp icon from UIActivityViewController and watsapp user list appear.

But there is a cancel button on that screen from where user can cancel sharing but still you will get completed flag true so there is no way you can detect if user click on cancel button from watsapp user list.

like image 110
Dharmesh Kheni Avatar answered Nov 05 '22 17:11

Dharmesh Kheni