2016-09-26 14 views
0

UNUserNotificationCenterのデリゲートを拡張しようとしています。 Appleのドキュメントによれば、これはdidFinishLaunchingWithOptionsで行われなければなりません。 (https://developer.apple.com/reference/usernotifications/unusernotificationcenterdelegateNativeScriptはUNUserNotificationCenterデリゲートを拡張します

アプリケーションのこの部分でコードを実行する方法については、既にドキュメントがあります。しかし、私はこれがどのように動作するかの意味を理解しているかどうかわかりません。ここで私は、プロパティを委任UNUserNotificationCenterDelegateを拡張し、現在のセンターに割り当てることを試みたが、私はローカル通知を受け取るときに、2つの機能のどちらが実行されています。これを行うの

if (application.ios) { 


    var __extends = this.__extends || function (d, b) { 
     for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; 
     function __() { this.constructor = d; } 
     __.prototype = b.prototype; 
     d.prototype = new __(); 
    }; 

    var appDelegate = (function (_super, _notiCenter) { 
     __extends(appDelegate, _super); 

     function appDelegate() { 
      _super.apply(this, arguments); 
     } 

     function UNUserNotificationCenterDelegate(){ 
      _notiCenter.apply(this, arguments); 
     }  

     appDelegate.prototype.applicationDidFinishLaunchingWithOptions = function (application, launchOptions) { 

     UNUserNotificationCenterDelegate.prototype.userNotificationCenterDidReceiveNotificationResponseWithCompletionHandler = function(center, notif, completion){ 
       console.log('We are here'); 
      } 

      UNUserNotificationCenterDelegate.prototype.userNotificationCenterWillPresentNotificationWithCompletionHandler = function(center, notif, completion){ 
       console.log('We are here 2'); 
      }  

      var center = utils.ios.getter(UNUserNotificationCenter, UNUserNotificationCenter.currentNotificationCenter); 

      center.delegate = UNUserNotificationCenterDelegate; 

     }; 


     appDelegate.ObjCProtocols = [UIApplicationDelegate]; 
     return appDelegate; 

    })(UIResponder, UNUserNotificationCenterDelegate); 

    application.ios.delegate = appDelegate; 

} 

答えて

0

正しい方法は追加して、以下の通りでありますUSUserNotificationCenterDelegateappDelegate.ObjCProtocolsアレイ:

if (application.ios) { 

    var __extends = this.__extends || function (d, b) { 
     for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; 
     function __() { this.constructor = d; } 
     __.prototype = b.prototype; 
     d.prototype = new __(); 
    }; 

    var appDelegate = (function (_super) { 

     __extends(appDelegate, _super); 

     function appDelegate() { 
      _super.apply(this, arguments); 
     } 

     appDelegate.prototype.userNotificationCenterDidReceiveNotificationResponseWithCompletionHandler = function(center, notif, completion){ 
      completion(); 
     } 

     appDelegate.prototype.userNotificationCenterWillPresentNotificationWithCompletionHandler = function(center, notif, completion){ 
      completion(4); 
     }  

     appDelegate.prototype.applicationDidFinishLaunchingWithOptions = function (application, launchOptions) { 

      var center = utils.ios.getter(UNUserNotificationCenter, UNUserNotificationCenter.currentNotificationCenter); 
      center.delegate = this; 

     }; 

     appDelegate.ObjCProtocols = [UIApplicationDelegate, UNUserNotificationCenterDelegate]; 
     return appDelegate; 

    })(UIResponder); 

    application.ios.delegate = appDelegate; 

} 
関連する問題