0

I'm asking for help, I'm trying to implement the function of publishing videos from my application to other platforms, to replenish the internal balance Problem with rail instagram : After a successful publication, the activity controller goes into the start state and my application does not know that the rail has been published, because of this, coins are not awarded for this type of publication, since the completionWithItemsHandler method does not work

here is my share function:

   @objc func shareData(sender: UIButton){
        self.shareVideoForIndex(index: sender.tag)
   }

    func shareVideoForIndex(index : Int){
        let videoData = videoSearchData[index]
        let fileID = videoData.video_ID
        let videoURL = URL.videoMixesDir.appendingPathComponent(videoData.video_URL)
        let isAlreadyShared = videoData.isAlreadyPostOnSocial
        
        let shareAll: [URL] = [videoURL]
        let arrayOfItem = shareAll.map { url in
            ShareItem(url: url , title: "")
        }
    
        let activityViewController = UIActivityViewController(activityItems: arrayOfItem, applicationActivities: nil)
        activityViewController.setValue("Video", forKey: "subject")
        activityViewController.completionWithItemsHandler = {
            activityType, completed, returnedItems, error in
                if completed && (error == nil) {
                    Analytics.logEvent("did_tap_share_button", parameters: ["type": activityType?.rawValue as Any])
                if activityType == UIActivity.ActivityType.postToFacebook ||
                    activityType == UIActivity.ActivityType.postToTwitter ||
                    activityType == UIActivity.ActivityType("com.burbn.instagram.shareextension") ||
                    activityType == UIActivity.ActivityType("com.burbn.youtube.shareextension") {
                    
                    if activityType == UIActivity.ActivityType("com.burbn.instagram.shareextension"){
                        let asset = AVAsset(url: videoURL)
                        let duration = asset.duration.seconds
                        if !(duration < 60){
                            return
                        }
                    }
                   
                    if !isAlreadyShared {
                        let totalCoin = self.keyChain.get(CoinsStoreController.coinsKey) ?? ""
                        var IntCoin = Int(totalCoin) ?? CoinsStoreController.premiumMixCost * 3
                        IntCoin = IntCoin + 25
                        self.keyChain.set("\(IntCoin)", forKey: CoinsStoreController.coinsKey, withAccess: .none)
                        DataBaseVideoRecord.shareInstance.updateVideoDataForSharedStatus(
                            videoID: fileID,
                            sharedStatus: true
                        )
                        DispatchQueue.main.async {
                            let alertController = UIAlertController(
                                title: "",
                                message: "You just earned 25 bonus coins!",
                                preferredStyle: .alert
                            )
                            self.navigationController?.present(alertController, animated: true) {
                                DispatchQueue.main.asyncAfter(deadline: .now() + 6.0) {
                                    alertController.dismiss(animated: true, completion: nil)
                                }
                            }
                        }
                    }
                }
            }
        }
        activityViewController.popoverPresentationController?.sourceView = self.view
        self.present(activityViewController, animated: true, completion: nil)
    
    }

A normal post, sms or story closes the activity controller by itself and everything works, but not reels I found that the value of completed is returned false on successful rail posting

0 Answers0