2016-03-30 28 views
9

İlk önce bunun gerçekten güzel bir eklentidir (https://github.com/katzer/cordova-plugin-local-notifications) ama çalışmanın bazı zorlukları olduğunu söylemek istedim.Cordova Phonegap yerel bildirimler çalışmıyor

Android ve Phonegap CLI kullanıyorum. Bütün bu kombinasyonları denedi benim config.xml olarak

<preference name="phonegap-version" value="3.5.0" />

:

<plugin name="de.appplant.cordova.plugin.local-notification" spec="0.8.1" source="pgb" /> 
<gap:plugin name="de.appplant.cordova.plugin.local-notification" /> 
<plugin name="de.appplant.cordova.plugin.local-notification" source="pgb" /> 

Ancak ben hem CLI 5.0 ve şimdi PhoneGap 3.5.0 denedi, bu benim Config.xml olduğunu bildirimler görünmez - telefonda hiçbir şey olmaz - hiçbir şey, nada, zilch. Ayrıca kitchensink App (https://github.com/katzer/cordova-plugin-local-notifications/tree/example) indirilen ve inşa PhoneGap yüklü ve telefonum ve hiçbir şey tekrar olur gelmiş ..

Bu benim kodudur index.html yüzden telefon yangınları asap yerel bildirim kayıt olmalıdır:

hiçbir şey telefonda olur ?? -
cordova.plugins.notification.local.registerPermission(function (granted) { 
    // console.log('Permission has been granted: ' + granted); 
}); 

cordova.plugins.notification.local.schedule({ 
    id: 1, 
    title: 'Reminder', 
    text: 'Dont forget to pray today.', 
    every: 'minute', 
    icon: 'res://icon', 
    smallIcon: 'res://ic_popup_sync' 
}); 

Ben de bile kitchensink uygulaması çalışmıyor

cordova.plugins.notification.local.schedule({ 
    id: 2, 
    text: "Good morning!", 
    firstAt: tomorrow_at_8_am, 
    every: "day" // "minute", "hour", "week", "month", "year" 
}); 

çalıştı

Benim Android sürümü: 5.1.1

nasıl yerel bildirimler PhoneGap görünmesini alabilirim?

+0

Deviceready etkinliğinin ateşlendiğini doğruladınız mı? – chadiusvt

+0

Evet, uygulama buna yanıt veriyor. Ben Phonegap kurmak ve telefonda bir .apk yapımında konsol.log ve çeşitli diğer testler yaptım - mutfak lavabo uygulaması – TheBlackBenzKid

+0

@ TheBlackBenzKid Merhaba, ben sadece kitchensink uygulaması ile çalışıyoruz çalışıyor. Yarın bilmene izin verecek.Ama örnek kodu indirirken fark ettiğim bir şey eklenti klasörünün düzgün şekilde alınmıyor olmasıdır. Eklentiler içinde 'de.appplant.cordova.plugin.local-notification' klasörünü bulamıyorum. Sadece 1kb boyutunda 'de.appplant.cordova.plugin.local-notification' dosyasını görebiliyordum. Eklentinizin, eklenti klasörünüzde aynı şekilde kontrol edilerek doğru şekilde kurulduğunu doğrulayabilir misiniz? – Gandhi

cevap

3

ben de ben & çalışma bu eklentiyi almaya çalışırken uzun saatler geçirdim, ama en iştahlı biri olarak buluyorsunuz. html etiketinde Şimdi

var testNotifications = function() { 

document.addEventListener("deviceready", function() { 

    console.warn("testNotifications Started"); 

    // Checks for permission 
    cordova.plugin.notification.local.hasPermission(function (granted) { 

    console.warn("Testing permission"); 

    if(granted == false) { 

     console.warn("No permission"); 
     // If app doesnt have permission request it 
     cordova.plugin.notification.local.registerPermission(function (granted) { 

     console.warn("Ask for permission"); 
     if(granted == true) { 

      console.warn("Permission accepted"); 
      // If app is given permission try again 
      testNotifications(); 

     } else { 
      alert("We need permission to show you notifications"); 
     } 

     }); 
    } else { 

     var pathArray = window.location.pathname.split("/www/"), 
      secondLevelLocation = window.location.protocol +"//"+ pathArray[0], 
      now = new Date(); 


     console.warn("sending notification"); 

     var isAndroid = false; 

     if (device.platform === "Android") { 
     isAndroid = true; 
     } 

     cordova.plugin.notification.local.schedule({ 
      id: 9, 
      title: "Test notification 9", 
      text: "This is a test notification", 
      sound: isAndroid ? "file://sounds/notification.mp3" : "file://sounds/notification.caf", 
      at: new Date(new Date().getTime() + 10) 
      // data: { secret:key } 
     }); 

    } 

    }); 

    }, false); 

}; 

- - senin js içinde

<button onclick="testNotifications()">Test notification</button> 
o Ayrıca üst uç bildirimlerinizi emin olmaktır izinleri gerektiği yönünde bir bildirim veya uyarmalıdır

Projenin kökünde bir klasörde.android mp3 ve ios caf olmalıdır

1

Cevap 1:

sürümü 3.5.0 için plugin's plugin.xml de bakabilirsiniz. bkz hat eklentisi demektir 22

<engine name="cordova" version=">=3.6.0" /> 

sadece 3.6.0 daha versiyon daha destekler ve 3.5.0

Cevap 2 kullanıyor: sürüm 5.0 veya üstü

deneyin için aşağıdaki kodu index.html olarak takip edebilirsiniz. o zaman mükemmel çalışırsa ve notification.schedule için diğer seçenekler. biz sağlanmadığı gibi (hemen) seçenek bildirimi hemen tetiklenecektir.

<html> 
<script type="text/javascript" src="cordova.js"></script> 
<script> 
document.addEventListener('deviceready', onDeviceReady.bind(this), false); 
     function onDeviceReady() {        
      cordova.plugins.notification.local.schedule({ 
       id: 1, 
       title: "Sample Notification", 
       text: "foo",      
       every: "week",           
       data: { meetingId: "123#fg8" } 
      }); 
     }; 
</script> 
<body> 
</body> 
</html> 
İlgili konular