katzer / cordova-plugin-local-notifications

Cordova Local-Notification Plugin
Apache License 2.0
2.57k stars 1.76k forks source link

Can't get working in IOS 8.1.3 with phonegap build #427

Closed neil-rowe closed 9 years ago

neil-rowe commented 9 years ago

I'm using ver 0.7.8 which should support IOS8 using phone gap build 3.7.0 on iPhone5 with IOS 8.1.3

I'm trying to set a notification with a simple onclick event which is of course being called long after the device is ready. - the alert is just so i know i actually click the element and the script is running. but no notifications are ever fired whether the app is in background or not at the 7 seconds when the notification should be fired. . i haven't had to use the cancel function yet since the basic notification isn't working, but its there to cancel any repeating tests. my script is below. the alert works fine. ..just no notifications fired. any help would be greatly appreciated.

var alarm1 = function() { alert('you clicked it alright'); window.plugin.notification.local.hasPermission(function () {

    var now  = new Date().getTime(),
        _60_seconds_from_now = new Date(now + 7*1000);

    window.plugin.notification.local.add({ 
        id: 'new',
        date: _60_seconds_from_now,
        message: 'finally!',
        badge: 1,
    });
});

};

var alarmCancelAll = function() { window.plugin.notification.local.cancelAll(); };

$('.add-alarm').click(function() { alarm1(); });

$('.cancel-alarm').click(function() { alarmCancelAll(); });

rkj1515 commented 9 years ago

Register Notification permission in IOS 7 and above: add following code in appDelegate.m class's :application:didFinishLaunchingWithOptions: method

    [application registerUserNotificationSettings:
        [UIUserNotificationSettings settingsForTypes:
            UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
neil-rowe commented 9 years ago

Ok so I've updated to v 8.0 of the plugin, and I've implemented the lines you suggested. my script is now as follows:

document.addEventListener('deviceready', function () { var alarm1 = function() { alert('you clicked it alright');

    var now  = new Date().getTime(),
        _60_seconds_from_now = new Date(now + 4*1000);

    window.plugin.notification.local.schedule({
        id:         1,  // A unique id of the notifiction
        text:    "ciao",  // The message that is displayed
        title:      "My app",  // The title of the message
        date: _60_seconds_from_now,
    });
};

var alarmCancelAll = function() {
    window.plugin.notification.local.cancelAll();
};

$('.add-alarm').click(function() {
    alarm1();
});

$('.cancel-alarm').click(function() {
    alert('you clicked cancel');

    alarmCancelAll();
});

}, false);

window.plugin.notification.local.on("schedule", function(notification) { alert("scheduled: " + notification.id); });

..and here is the addition to my AppDelegate.m file

... /**

if __has_feature(objc_arc)

    self.window = [[UIWindow alloc] initWithFrame:screenBounds];

else

...

that is lines 61-74 of the file now. does this look right? aside from getting a notification to schedule it would seem that i can't even find the available functions of the plugin if I'm doing a quick

if (typeof plugin.notification.local.schedule == 'function') { alert('function exits!'); }

on $(document).ready

any thoughts?

neil-rowe commented 9 years ago

app just freezes trying to check if the function exists.

neil-rowe commented 9 years ago

do you need include the local-notification.js pointer in the index file?

it just seems like the plugin is not initializing at all since when i check for the methods they return as undefined. I'm executing within deviceready

katzer commented 9 years ago

hi @neil-rowe,

I suggest you to checkout the sample app and start playing with that code base. There is also a note about iOS 8 permission.

app just freezes trying to check if the function exists.

That happens because you seems to call that before device is ready (and plugin is loaded).

neil-rowe commented 9 years ago

Thanks Katzer,

The sample app runs great on the Xcode simulator, and I've gotten the 8.0 version to run as well. but I've decided to just go with 7.5 since it supports iOS 8 (from what i understand) and its available on phone gap build. i get a response from permissions being set to allow notifications, but when i try to set a notification the app crashes and exits. same thing happens when i run my own fork of ver 8.0rc through phone gap build and switch the methods over to the new language accordingly. I have other plugins running, but this one seems to crash out with ether version. It seems to work once when i just install the app and then fire one right away every now and then, but from there on out it just kills the app.

Im on iOS 8.1.3 and trying both ver 7.5 and ver 8.0rc respectively though phone gap build.

any ideas?

neil-rowe commented 9 years ago

K I've got it working now! thanks for all your work on this great plugin btw. its really useful, and should really be a core phongap plugin in my opinion.

katzer commented 9 years ago

Thanks! What was the reason?

neil-rowe commented 9 years ago

well.. long story as short as i can tell it, I am using phonegap build so that complicated things a little in that i had to fork your 8.0rc version to my own and upload my own plugin to build from it (which is awesome that you can do that now!) , but I'm also building a hybrid app that runs off a dedicated remote site and does not operate from the local index page. So basically I had to copy over all plugin.js as well as cordova_plugins.js and platform specific cordova.js versions to my server. once they were there i had to wrap the plugin specific js in:

cordova.define("de.appplant.cordova.plugin.local-notification.LocalNotification", function(require, exports, module) {

});

because i wasn't building it elsewhere to have this added. then i had some config.xml issues from another setup i had tried which was giving me issues with phonegap build so i rebuilt my config file from a fresh build sample one and left out anything extraneous. but in the end the biggest issue was getting the cordova scripts to load on the page in the right order. Once I took loading out of Jquery and moved it to my php and loaded cordova.js LAST after all other scripts, it functions just fine. ..Im loading cordova.js conditionally through one line of quick php browser checking, so it loads the proper version for iOS or Android. But in the end it DOES in fact work to run the phonegap API from a remote page. ..works great actually. The page remote page itself is not really accessible via desktop and only loads in-app, so its really a dedicated platform for the app, but it allows for using the whole remote site as a phonegap enabled hybrid web app. pretty sweet! (and yes for anyone else.. Apple does actually accept apps like this if they function seemlessly/fluidly as an app. especially if your tying into native phone features) thanks again for the help and encouragement. ..i definitely needed it in working through this one :)