gpt4 book ai didi

ios - 初始化推送通知时 ionic 的奇怪内存泄漏导致卡住

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:02:13 26 4
gpt4 key购买 nike

几天以来,我遇到了一些非常奇怪的内存问题。

问题是,有时应用程序会卡住并开始快速增加内存使用量,直到崩溃。当内存增加时,应用程序完全卡住。

经过一些调试后,我确定是这段代码导致了错误:

angular.module('app.shared').factory('PushNotificationService',         PushNotificationService);

PushNotificationService.$inject = [
'$q',
'MessagingService'
];

function PushNotificationService($q, MessagingService) {
var me = this;

initialize();

return {
getStartupMessage: getStartupMessage,
fetchToken: fetchToken
};

/**
* Constructor
* @return {[type]} [description]
*/
function initialize() {
me.pusher = null;
me.deviceToken = null;
me.startupMessage = null;
}

/**
* Fetches the push token through device interface
*
* @return {$q} Promises
*/
function fetchToken() {
if (me.pusher != null) {
return $q(function(resolve, reject) {
console.log('PushService.fetchToken(): Got pusher', me.pusher);

// when pusher was already initialized, we do not need to fetch it again
console.log('PushService.fetchToken(): Token was already retrieved', me.deviceToken);
resolve(me.deviceToken);
});
}

console.log('PushService.fetchToken(): Needs to fetch token bc not retrieved yet');

return $q(function(resolve, reject) {
document.addEventListener('deviceready', function() {
console.log('PushService.fetchToken(): Device is ready', typeof resolve, typeof reject);

resolve(true);
}, false);
}).then(function() {
console.log('PushService.fetchToken(): No pusher retrieved yet, do it now');

return __initialize();
}).then(function(push) {
console.log('PushService.fetchToken(): Got pusher and start attaching events to it', push);

return $q(function(resolve, reject) {
push.on('error', function(error) {
console.log('PushNotificationService.fetchToken(): Error while retrieving token', error.message, error);

reject(error);
});

push.on('registration', function(data) {
console.log('PushNotificationService.fetchToken(): Successfully retrieved token', data);

me.deviceToken = data.registrationId;

resolve(data.registrationId);
});

console.log('PushNotificationService.fetchToken(): Eventhandlers of pusher', push._handlers);
});
});
}

/**
* Initializes the push notifications and tries to fetch the Push token
* @return {Cordova.Pusher} [description]
*/
function __initialize() {
me.pusher = PushNotification.init({
android: {
senderID: "288503736094"
},
ios: {
alert: true,
badge: true,
sound: true,
clearBadge: true
},
windows: {}
});

me.pusher.on('notification', __incomingNotification);

return me.pusher;
}

// additional code which is not relevant here...
// .....
// .....
}

它只发生在 iOS 上并且完全随机,无法在崩溃中找到系统。

调试日志如下所示:

PushService.fetchToken(): Needs to fetch token bc not retrieved yet 

PushService.fetchToken(): Device is ready function function

PushService.fetchToken(): No pusher retrieved yet, do it now

PushService.fetchToken(): Got pusher and start attaching events to it {"_handlers":{"registration":[],"notification":[null],"error":[]},"options":{"android":{"senderID":"288503736094"},"ios":{"alert":true,"badge":true,"sound":true,"clearBadge":true},"windows":{}}}

PushNotificationService.fetchToken(): Eventhandlers of pusher {"registration":[null],"notification":[null],"error":[null]}

最佳答案

这是 cordova-ios 中的一个问题,导致随机位置发生大量内存泄漏。

升级到最新版本修复了它!

关于ios - 初始化推送通知时 ionic 的奇怪内存泄漏导致卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35841820/

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