도와주세요! 푸시 알림 데모를 수정하기 위해 일주일 동안 노력했지만 여전히 작동하지 않습니다! 애플리케이션을 종료 한 후 기기에서 메시지를 수신하지 못했습니다.Worklight : Android에서 푸시 알림 오류
이 (브라우저 키) 응용 프로그램 descriptor.xml 파일에서 안드로이드 요소는 :
$('#isSupportbtn').bind("click", isSupport);
$('#isSubscibedbtn').bind("click",isSubscribed);
$('#subscribebtn').bind("click",doSubscribe);
$('#unSubscribebtn').bind("click",doUnSubscribe);
function isSupport(){
var isSupport = false;
if(WL.Client.Push){
isSupport = WL.Client.Push.isPushSupported();
}
alert(isSupport);
}
function isSubscribed(){
var isSubscribed = false;
if(WL.Client.Push){
isSubscribed = WL.Client.Push.isSubscribed('myPush');
}
alert(isSubscribed);
}
if(WL.Client.Push){
WL.Client.Push.onReadyToSubscribe = function(){
$('#subscribebtn').removeAttr('disabled');
$('#unSubscribebtn').removeAttr('disabled');
WL.Client.Push.registerEventSourceCallback(
"myPush",
"AdapterAuth",
"pushEventSource",
pushNotificationReceived
);
};
}
function doSubscribe(){
WL.Client.Push.subscribe("myPush",{
onSuccess:function(){
alert("Success");
},
onFailure:function(){
alert("Fail");
}
});
}
function doUnSubscribe(){
WL.Client.Push.unsubscribe("myPush",{
onSuccess:function(){
alert("Success");
},
onFailure:function(){
alert("Fail");
}
});
}
function pushNotificationReceived(props, payloads){
alert("pushNotificationReceived invoked");
alert("props :: " + JSON.stringify(props));
alert("payload :: " + JSON.stringify(payload));
}
이것은 AdapterAuth-impl.js입니다 :
<android version="1.0" securityTest="mobile-securityTest">
<worklightSettings include="false"/>
<pushSender key="AIzaSyBmDTJw8IQAA1MmTF9MkSQUQXYxoFBKKtk" senderId="430560385547"/>
<security>
<encryptWebResources enabled="false"/>
<testWebResourcesChecksum enabled="false" ignoreFileExtensions="png, jpg, jpeg, gif, mp4, mp3"/>
<publicSigningKey>PushNotificationMyAppAndroid</publicSigningKey>
<packageName>com.MyApp</packageName>
</security>
<compressWebResources enabled="true"/>
</android>
이 main.js 파일입니다 파일 :
:function getUser() {
return {Data:[{username:'hcv',password:"123456",bagde:'3',message:'hi, Jane'},{username:'vi',password:'123',bagde:'3',message:'hi, Luffy'}]};
}
function onAuthRequired(headers,errorMessage){
errorMessage = errorMessage ? errorMessage:null;
return{
authRequired:true,
errorMessage:errorMessage
};
}
function submitAuth(username,password) {
var response = {Data:[{username:'hcv',password:"123456",bagde:'3',message:'hi, Jane'},{username:'vi',password:'123',bagde:'3',message:'hi, Luffy'}]};
for (var i=0;i<response.Data.length;i++){
if(username === response.Data[i].username && password === response.Data[i].password){
var Identity={
userId: username,
displayName: username,
attributes:{foo:"bar"}
};
WL.Server.setActiveUser("AuthLoginRealm", Identity);
return{
authRequired: false
};
}
}
return onAuthRequired(null,"Invalid login credentials");
}
function onLogout(){
WL.Server.setActiveUser("AuthLoginRealm", null);
WL.Logger.debug("Logged out");
}
WL.Server.createEventSource({
name:"pushEventSource",
poll:{
interval:60,
onPoll:"submitNotifications"
},
securityTest:"mobile-securityTest",
});
function submitNotifications() {
var response = {Data:[{username:'hcv',password:"123456",bagde:"3",message:"hi,Jane"},{username:"vi",password:"123",bagde:"1",message:"hi, Luffy"}]};
var messages = response.Data;
for(var i=0; i < messages.length;i++){
var userId = WL.Server.getActiveUser("AuthLoginRealm");
if(messages[i].username === userId){
var userSubscription = WL.Server.getUserNotificationSubscription("AdapterAuth.pushEventSource", messages[i].username);
if(userSubscription === null){
return {result:"no user was found:"+messages[i].username};
}
var notification = WL.Server.createDefaultNotification(messages[i].message, messages[i].bagde,{foo:'bar'});
WL.Logger.debug("submitNotification >> userId :: " + messages[i].username + ", text :: " + messages[i].message);
WL.Server.notifyAllDevices(userSubscription, notification);
WL.Logger.error("UserId"+messages[i].username+"not found");
}
}
}
이 오류입니다
06-24 09:27:11.927: E/ActivityThread(3096): Activity com.MyApp.MyApp has leaked IntentReceiver [email protected] that was originally registered here. Are you missing a call to unregisterReceiver()?
06-24 09:27:11.927: E/ActivityThread(3096): android.app.IntentReceiverLeaked: Activity com.MyApp.MyApp has leaked IntentReceiver [email protected] that was originally registered here. Are you missing a call to unregisterReceiver()?
06-24 09:27:11.927: E/ActivityThread(3096): at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:763)
06-24 09:27:11.927: E/ActivityThread(3096): at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:567)
06-24 09:27:11.927: E/ActivityThread(3096): at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1055)
06-24 09:27:11.927: E/ActivityThread(3096): at android.app.ContextImpl.registerReceiver(ContextImpl.java:1042)
06-24 09:27:11.927: E/ActivityThread(3096): at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:348)
06-24 09:27:11.927: E/ActivityThread(3096): at com.google.android.gcm.GCMRegistrar.setRetryBroadcastReceiver(GCMRegistrar.java:293)
06-24 09:27:11.927: E/ActivityThread(3096): at com.google.android.gcm.GCMRegistrar.register(GCMRegistrar.java:215)
06-24 09:27:11.927: E/ActivityThread(3096): at com.worklight.androidgap.plugin.Push.subscribe(Push.java:331)
06-24 09:27:11.927: E/ActivityThread(3096): at com.worklight.androidgap.plugin.Push.access$400(Push.java:45)
06-24 09:27:11.927: E/ActivityThread(3096): at com.worklight.androidgap.plugin.Push$2.run(Push.java:233)
06-24 09:27:11.927: E/ActivityThread(3096): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
06-24 09:27:11.927: E/ActivityThread(3096): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
06-24 09:27:11.927: E/ActivityThread(3096): at java.lang.Thread.run(Thread.java:856)
샘플 푸시 알림 프로젝트를 사용해 보셨습니까? –
예, 했어요 ... 괜찮습니다. – HCV
방금 내 오류를 추가했습니다. 응용 프로그램을 종료 한 후에 발생합니다 ... – HCV