4

I'm building a simple alarm clock with Phonegap for ios, and I've got the notifications triggering on background and foreground. (All with the help of Drew Dahlman and this tutorial http://www.drewdahlman.com/meusLabs/?p=84).

The phonegap plugin provides the capability to run background and foreground functions when the localNotification is triggered.

My problem is that if the app is in the background, I seem to only be getting a default "close/view" dialog box, not the notification dialog box I'm setting. I was hoping to have the background notification give the user the ability to "get up" or "snooze", but of course, this isn't possible with the default "close/view" notification.

Have I got this wrong? Is there another way around this?

My code for setting the local notification is simple

plugins.localNotification.add({ date: set_alarm, 
                               message:"background",  
                               badge: 1, 
                               id: 12, 
                               sound:'Alarm_01.caf',
                               background:'MyApp.Alarm.notification_background',
                               foreground: 'MyApp.Alarm.notification_foreground'
                             });

Foreground notifications work fine, it's just the background notification I'm struggling with.

pedalpete
  • 21,076
  • 45
  • 128
  • 239
  • after doing some research and digging - looks like this could be a nice addition - adding custom buttons to the notification... http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW1 looks like you can customize the buttons. I am going to continue to dig, if you want to take it up and do this - please fork the git repo and I will make it officially a part of the plugin. – Drew Dahlman Jul 26 '12 at 05:02
  • Thanks Drew. I've never done an Objective C, kinda out of my field of expertise. I looked through that documentation earlier, and thought it said you could create titles and actions on those buttons, but now that I look at the UI Guildines (http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/MobileHIG/TechnologyUsage/TechnologyUsage.html#//apple_ref/doc/uid/TP40006556-CH18-SW11), it says you can only change the text of the action button. Don't want to send you on a wild goosechase on this, I'm not sure it's possible. What do you think? – pedalpete Jul 26 '12 at 06:53

1 Answers1

0

In your app delegate.m file you will need to activate the alarm or your local notification when the app has entered the background:

- (void)applicationDidEnterBackground:(UIApplication *)application

or

- (void)applicationWillResignActive:(UIApplication *)application

(depending on your needs) More documentation can be found here:

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html

My suspicion is that you have only configured the app to set off the alarm after –application:didFinishLaunchingWithOptions: and -application:didReceiveLocalNotification:

which is the default.

There are many other options:

Monitoring App State Changes

  • application:willFinishLaunchingWithOptions:
  • application:didFinishLaunchingWithOptions:
  • applicationDidBecomeActive:
  • applicationWillResignActive:
  • applicationDidEnterBackground:
  • applicationWillEnterForeground:
  • applicationWillTerminate:
  • applicationDidFinishLaunching:

Managing App State Restoration

  • application:shouldSaveApplicationState:
  • application:shouldRestoreApplicationState:
  • application:viewControllerWithRestorationIdentifierPath:coder:
  • application:willEncodeRestorableStateWithCoder:
  • application:didDecodeRestorableStateWithCoder:

Providing a Window for Storyboarding window property Managing the Default Interface Orientations

  • application:supportedInterfaceOrientationsForWindow:

Opening a URL Resource

  • application:openURL:sourceApplication:annotation:
  • application:handleOpenURL:

Managing Status Bar Changes

  • application:willChangeStatusBarOrientation:duration:
  • application:didChangeStatusBarOrientation:
  • application:willChangeStatusBarFrame:
  • application:didChangeStatusBarFrame:

Responding to System Notifications

  • applicationDidReceiveMemoryWarning:
  • applicationSignificantTimeChange:

Handling Remote Notifications

  • application:didReceiveRemoteNotification:
  • application:didRegisterForRemoteNotificationsWithDeviceToken:
  • application:didFailToRegisterForRemoteNotificationsWithError:

Responding to Content Protection Changes

  • applicationProtectedDataWillBecomeUnavailable:
  • applicationProtectedDataDidBecomeAvailable: