GCM을 사용하여 사용자 브라우저에 알림을 보냈습니다. GCM 서비스를 등록하려면크롬 확장 프로그램에서 gcm 등록 취소 방법
function registerCallback(registrationId) {
if (chrome.runtime.lastError) {
// When the registration fails, handle the error and retry the
// registration later.
return;
}
// Send the registration token to your application server.
sendRegistrationId(function(succeed) {
// Once the registration token is received by your server,
// set the flag such that register will not be invoked
// next time when the app starts up.
if (succeed)
chrome.storage.local.set({registered: true});
});
}
function sendRegistrationId(callback) {
// Send the registration token to your application server
// in a secure way.
}
chrome.runtime.onStartup.addListener(function() {
chrome.storage.local.get("registered", function(result) {
// If already registered, bail out.
if (result["registered"])
return;
// Up to 100 senders are allowed.
var senderIds = ["Your-Sender-ID"];
chrome.gcm.register(senderIds, registerCallback);
});
});
내 확장 프로그램이 GCM과 연결되어 있고 사용자 브라우저에 알림을 보내고 있습니다. 내 질문은 사용자가 확장 프로그램을 제거 할 때 GCM 토큰을 등록 해제하는 방법입니다. Chrome 확장 프로그램에는 제거 이벤트가 없습니다. 내 크롬 확장에 GCM 연결 코드 등록을 취소 할 곳을 알려주십시오. 사용자가이를 제거 할 때 내 확장 (background.js, contentscript.js)에서이 코드를 작성
..function unregisterCallback() {
if (chrome.runtime.lastError) {
// When the unregistration fails, handle the error and retry
// the unregistration later.
return;
}
}
chrome.gcm.unregister(unregisterCallback);
. 이제 알림이 사용자에게 전달되지 않으면 등록 해제가 필요한 이유는 무엇입니까? –
안녕하세요, 회신 해 주셔서 감사합니다. Chrome 확장 프로그램을 설치하고 여러 번 제거하여 내 PC에서 내 확장 프로그램을 테스트 할 때마다 GCM ID가 만드는 모든 설치 (10 번 설치하면 10 개의 GCM ID가 생성됨)가됩니다. 사용자에게 알림을 보낼 때마다 GCM ID가 등록되지 않았기 때문에 10 개의 알림을 받고있었습니다. 등록을 취소하려면 어디에서 내 확장 기능을 사용해야할지 모르겠다. – Java4you
@ Java4you 나는 똑같은 문제를 다루고 있습니다 :) 이것에 대한 해결책을 찾았습니까? –