gpt4 book ai didi

ios - NativeScript 扩展了 UNUserNotificationCenter 委托(delegate)

转载 作者:行者123 更新时间:2023-11-28 21:21:25 26 4
gpt4 key购买 nike

我正在尝试扩展 UNUserNotificationCenter 的委托(delegate)。根据 Apple 文档,这必须在 didFinishLaunchingWithOptions 中完成。 ( https://developer.apple.com/reference/usernotifications/unusernotificationcenterdelegate )

关于如何让代码在应用程序的这一部分运行的文档已经存在。但是,我有点不确定我是否理解其工作原理的语义。在这里,我尝试扩展 UNUserNotificationCenterDelegate 并将其分配给当前的中心委托(delegate)属性,但是当我收到本地通知时,这两个函数都没有运行:

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;

}

最佳答案

正确的做法如下,将 USUserNotificationCenterDelegate 添加到 appDelegate.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;

}

关于ios - NativeScript 扩展了 UNUserNotificationCenter 委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39701209/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com