• Apfeltalk ändert einen Teil seiner Allgemeinen Geschäftsbedingungen (AGB), das Löschen von Useraccounts betreffend.
    Näheres könnt Ihr hier nachlesen: AGB-Änderung
  • Die Bildungsoffensive hier im Forum geht weiter! Jetzt sollen Kreativität und technische Möglichkeiten einen neue Dimension erreichen. Das Thema in diesem Monat lautet - Verkehrte Welt - Hier geht es lang --> Klick

Zwei Fragen zu eigener Taschenlampen App

Thaddäus

Golden Noble
Registriert
27.03.08
Beiträge
18.662
Hi Leute...

Ich bastel mir hier grad eine Taschenlampen App (ja ich weiss, es gibt davon viele im Appstore, ist auch nur für mich privat).

Die App ist im Prinzip nix anderes als zwei Grafiken, die halt über AVFoundation.framework den LED-Blitz des iPhone 4 ansteuern. Doch nun folgendes Szenario:

Ich schalte den Blitz an, und drücke den Powerbutton. Damit erlischt der Blitz, soweit klar. Wenn ich nun aber wieder anschalte, dann zeigt mir die App obwohl die LED nicht leuchtet die Grafik für "Taschenlampe aus". Somit sind danach die Grafiken vertauscht, und stimmen nicht mit dem LED-Status überein. Wie bringe ich also Xcode dazu, den Status der LED (on oder off) zu prüfen, und entsprechend die korrekte Grafik zu wählen?

Hier ist mein delegate.m Code:

Code:
[COLOR=#c0269d]@implementation[/COLOR] TestAppDelegate



- ([COLOR=#c0269d]void[/COLOR])applicationDidFinishLaunching:([COLOR=#753ba4]UIApplication[/COLOR] *)application 
{   
[COLOR=#008523]// Create and initialize the window[/COLOR]
[COLOR=#421b7c][COLOR=#4c8186]window[/COLOR][COLOR=#000000] = [[[/COLOR][COLOR=#753ba4]UIWindow[/COLOR]alloc[COLOR=#000000]] [/COLOR]initWithFrame[COLOR=#000000]:[[[/COLOR][COLOR=#753ba4]UIScreen[/COLOR]mainScreen[COLOR=#000000]] [/COLOR]bounds[COLOR=#000000]]];[/COLOR][/COLOR]
[COLOR=#421b7c][COLOR=#000000]    [[ [/COLOR][COLOR=#753ba4]UIApplication[/COLOR]sharedApplication[COLOR=#000000] ] [/COLOR]setIdleTimerDisabled[COLOR=#000000]: [/COLOR][COLOR=#c0269d]YES[/COLOR][COLOR=#000000] ];[/COLOR][/COLOR]


[COLOR=#008523]// Create test view controller[/COLOR]
[COLOR=#4c8186]vc[COLOR=#000000] = [[[/COLOR]TestViewController[COLOR=#421b7c]alloc[/COLOR][COLOR=#000000]] [/COLOR][COLOR=#421b7c]init[/COLOR][COLOR=#000000]];[/COLOR][/COLOR]


[COLOR=#421b7c][COLOR=#000000]    [[/COLOR][COLOR=#4c8186]window[/COLOR]addSubview[COLOR=#000000]:[/COLOR][COLOR=#4c8186]vc[/COLOR][COLOR=#000000].[/COLOR][COLOR=#753ba4]view[/COLOR][COLOR=#000000]];[/COLOR][/COLOR]
[COLOR=#421b7c][COLOR=#000000]  [[/COLOR][COLOR=#4c8186]window[/COLOR]makeKeyAndVisible[COLOR=#000000]];[/COLOR][/COLOR]
}


- ([COLOR=#c0269d]void[/COLOR])applicationWillTerminate:([COLOR=#753ba4]UIApplication[/COLOR] *)application
  {  
      [application [COLOR=#421b7c]setIdleTimerDisabled[/COLOR]:[COLOR=#c0269d]NO[/COLOR]];
      }


- ([COLOR=#c0269d]void[/COLOR])dealloc 
{
[COLOR=#421b7c][COLOR=#000000]    [[/COLOR][COLOR=#4c8186]vc[/COLOR]release[COLOR=#000000]];[/COLOR][/COLOR]
[COLOR=#421b7c][COLOR=#000000]  [[/COLOR][COLOR=#4c8186]window[/COLOR]release[COLOR=#000000]];[/COLOR][/COLOR]
[COLOR=#421b7c][COLOR=#000000]  [[/COLOR][COLOR=#c0269d]super[/COLOR]dealloc[COLOR=#000000]];[/COLOR][/COLOR]
}


[COLOR=#c0269d]@end[/COLOR]

Und hier noch der Code aus dem controller.m:

Code:
- ([COLOR=#c0269d]void[/COLOR])buttonPressed:([COLOR=#753ba4]UIButton[/COLOR] *)button{
[COLOR=#4c8186][COLOR=#c0269d]if[/COLOR][COLOR=#000000] (button == [/COLOR]flashlightButton[COLOR=#000000])[/COLOR][/COLOR]
  {
[COLOR=#4c8186][COLOR=#c0269d]if[/COLOR][COLOR=#000000] ([/COLOR]flashlightOn[COLOR=#000000] == [/COLOR][COLOR=#c0269d]NO[/COLOR][COLOR=#000000])[/COLOR][/COLOR]
    {
[COLOR=#4c8186]flashlightOn[COLOR=#000000] = [/COLOR][COLOR=#c0269d]YES[/COLOR][COLOR=#000000];[/COLOR][/COLOR]
[COLOR=#421b7c][COLOR=#000000]      [[/COLOR][COLOR=#4c8186]flashlightButton[/COLOR]setBackgroundImage[COLOR=#000000]:[[/COLOR][COLOR=#753ba4]UIImage[/COLOR]imageNamed[COLOR=#000000]:[/COLOR][COLOR=#d52a25]@"TorchOff.png"[/COLOR][COLOR=#000000]] [/COLOR]forState[COLOR=#000000]:[/COLOR]UIControlStateNormal[COLOR=#000000]];[/COLOR][/COLOR]
      
    }
    [COLOR=#c0269d]else[/COLOR] 
    {        
[COLOR=#4c8186]flashlightOn[COLOR=#000000] = [/COLOR][COLOR=#c0269d]NO[/COLOR][COLOR=#000000];[/COLOR][/COLOR]
[COLOR=#421b7c][COLOR=#000000]          [[/COLOR][COLOR=#4c8186]flashlightButton[/COLOR]setBackgroundImage[COLOR=#000000]:[[/COLOR][COLOR=#753ba4]UIImage[/COLOR]imageNamed[COLOR=#000000]:[/COLOR][COLOR=#d52a25]@"TorchOn.png"[/COLOR][COLOR=#000000]] [/COLOR]forState[COLOR=#000000]:[/COLOR]UIControlStateNormal[COLOR=#000000]];    [/COLOR][/COLOR]
    }


[COLOR=#2f595d][COLOR=#000000]        [[/COLOR][COLOR=#c0269d]self[/COLOR]toggleFlashlight[COLOR=#000000]];[/COLOR][/COLOR]


  }
}

Das war mal Punkt 1. Und nun Punkt zwei. Ich fände es cool, wenn ich es hinbekommen würde, einen Button für das SOS Morsezeichen hinzuzufügen. Also dass die LED drei mal kurz, drei mal lang und dann nochmal drei mal kurz leuchet und das natürlich automatisch. Hat da jemand einen Tipp?

Wäre da für Hinweise dankbar.
 
Wenn das Display angeschaltet wird, wird diese Methode aufgerufen. Da kannst du den Status prüfen und entsprechend setzen.


Code:
[COLOR=#000000]-[/COLOR][COLOR=#000000]([/COLOR][COLOR=#00008B]void[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]applicationDidBecomeActive([/COLOR][COLOR=#2B91AF]UIApplication[/COLOR][COLOR=#000000]*)[/COLOR][COLOR=#000000]application
[/COLOR]