Apple Newton Utilities Guide de l'utilisateur Page 629

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 942
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 628
CHAPTER 17
Additional System Services
Using Additional System Services 17-13
The following code example removes all alarms an application has scheduled for
the next ve minutes:
foreach alarmKey in GetAppAlarmKeys(":MyApp:MySig") do
if not (GetAlarm(alarmKey).time > Time() + 5) then
RemoveAlarm (alarmKey);
Removing Installed Alarms 17
The functions RemoveAlarm and RemoveAppAlarms remove a particular alarm
and all of an application’s alarms, respectively. The
RemoveAlarm function takes
the alarm key of the alarm to remove as its single argument. Use of this function is
demonstrated in the code example in “Retrieving Alarm Keys” beginning on
page 17-12.
The
RemoveAppAlarms function takes an alarm key sufx as an argument and
removes all alarms whose key ends with this sufx. For this reason it is important
for all alarms created by a particular application to use alarm keys ending with the
same sufx. If your application’s alarm are not meaningful if your application is
not installed, you should call this function in your application’s
RemoveScript
function.
Common Problems With Alarms 17
This section describes common problems encountered with use of the alarm service.
Problems With Alarm Callback Functions 17
Alarms are kept in a soup; thus, they persist across restarts and installation or
removal of packages. This means that the arguments you pass to your callback
function are also stored in a soup; hence, these arguments are also copied deeply.
(See the description of the
DeepClone function in Newton Programmers
Reference.) Therefore, you must avoid indirectly referencing large objects lest
they unnecessarily inate the size of your entries in the alarm soup.
A classic example of accidentally referencing a large object is in dynamically
creating the function object executed with the alarm. Function objects may contain
references to the lexical environment and the current receiver (
self) at the time
they are created. For example, function objects created from a view method reference
the root view through their parent chain. If you pass such a function object to the
AddAlarm function, the system attempts to copy the entire root view into the
alarm soup. One way to minimize the size of your callback function object is to
pass as your callback a one-line function that invokes a method in your application
package to actually do the work.
Vue de la page 628
1 2 ... 624 625 626 627 628 629 630 631 632 633 634 ... 941 942

Commentaires sur ces manuels

Pas de commentaire