2016-05-26 1 views
1

Я только что внедрил Chartboost в мое быстрое приложение.Objective C Делегат в Swift

Я наградил межстраничные объявления. Поэтому мне нужно настроить делегата, используя объективную функцию C Chartboost. Я не могу понять, как это сделать. Так я сделал Admob через Swift.

NSNotificationCenter.defaultCenter().addObserver(self, selector: "presentInterstitial:", name: "AdMobCall", object: nil) 

    func presentInterstitial(sender:UIButton!) { 

    if let isReady = interstitial?.isReady { // _ isReady 
     interstitial?.presentFromRootViewController(self) 

    } 
} 

NSNotificationCenter.defaultCenter().postNotificationName("AdMobCall", object: nil) 

Но Objective функция C Chartboost я даюсь это:

  • (аннулируются) didCompleteRewardedVideo: (CBLocation) расположение withReward: (целое) вознаграждение;

И я не понимаю, как создать тот же самый делегат, который я сделал для Admob, используя эту функцию. это не представляется возможным. У меня есть Chartboost, награжденные межпартийными рабочими. Но у меня нет возможности настроить делегата, чтобы посмотреть, не посмотрели ли видео на завершение или нет.

ответ

0

Если вы хотите достичь цели-c делегировать в быстрый. Вам необходимо выполнить следующие шаги.

  1. нужно создать файл моста импортировать Objective-C классы

    // 
    // Use this file to import your target's public headers that you would like to expose to Swift. 
    // 
    
    #import "UVIViewController.h" 
    
  2. Вам необходимо продлить имя протокола в вашей быстрой ViewController

    import UIKit 
    
    class ViewController: UVIViewController, UVIDataRefreshProtocol { // 2. Extend Protocal 
    
        var secondController: DelegateViewController? 
    
        @IBOutlet var delegateRefresh: UILabel! 
    
        override func viewDidLoad() { 
         super.viewDidLoad() 
         // Do any additional setup after loading the view, typically from a nib. 
    
         self.registerForBasicDataRefreshNotification();    // 3. Register the protocol notification 
        } 
    
        override func didReceiveMemoryWarning() { 
         super.didReceiveMemoryWarning() 
         // Dispose of any resources that can be recreated. 
        } 
    
        // Register the protocol notification with same name. Example : DataRefreshNotification 
        override func registerForBasicDataRefreshNotification() { 
    
         self.validateBasicDataRefreshNotification(); 
         NSNotificationCenter.defaultCenter().addObserver(  // 4. Register the protocol notification with same name. 
          self, 
          selector: "basicDataDidRefresh", 
          name: DataRefreshNotification, 
          object: nil) 
    
        } 
    
        override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
         delegateRefresh.text = ""; 
         if segue.identifier == "view_to_delegate" { 
          secondController = segue.destinationViewController as? DelegateViewController 
         } 
        } 
    
        // Basic Data Did Refresh Notification 
        func basicDataDidRefresh() {       // 4. Event will be triggered while calling the protocol post notification. called with same name 
          NSLog("\n Basic data is refreshed") 
          delegateRefresh.text = "Basic data is refreshed"; 
        } 
    
    } 
    

5. NSNotificationCenter.defaultCenter().postNotificationName(DataRefreshNotification, object: nil) // Call the notification. 

Образец проекта: https://github.com/vigneshuvi/Objective-C-Delegate-Swift