 import AudioToolbox
 import AVFoundation
 
+protocol AlarmApplicationDelegate
+{
+    //typealias Weekday
+    func playAlarmSound()
+    func setNotificationWithDate(date: NSDate)
+    //something wrong with typealias, use Int instead
+    func setNotificationWithDate(date: NSDate, onWeekdaysForNotify:[Int])
+    func setupNotificationSettings()
+    
+    
+}
+
 @UIApplicationMain
-class AppDelegate: UIResponder, UIApplicationDelegate, AVAudioPlayerDelegate {
+class AppDelegate: UIResponder, UIApplicationDelegate, AVAudioPlayerDelegate, AlarmApplicationDelegate{
 
     var window: UIWindow?
     var audioPlayer: AVAudioPlayer?
+    //var alarmDelegate: AlarmApplicationDelegate?
+
 
     func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
         // Override point for customization after application launch.
-        
-        
-        application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound |
-            UIUserNotificationType.Alert | UIUserNotificationType.Badge, categories: nil))
+        //alarmDelegate? = self
+        //alarmDelegate!.setupNotificationSettings()
+        setupNotificationSettings()
         return true
     }
     
     func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {
-        
-        /*var alert = UIAlertView();
-        alert.title = "Get Notification";
-        alert.message = notification.alertBody;
-        alert.addButtonWithTitle(notification.alertAction!);
-        alert.show()*/
-        
-        
         
         /*AudioServicesAddSystemSoundCompletion(SystemSoundID(kSystemSoundID_Vibrate),nil,
             nil,
             vibrationCallback,
             nil)*/
+        
+        playAlarmSound()
+        //alarmDelegate!.scheduleNotification()
+  
+        
+    }
+    
+    //print out all registed NSNotification for debug
+    func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
+        
+        println(notificationSettings.types.rawValue)
+    }
+    
+    //AlarmApplicationDelegate protocol
+    func playAlarmSound() {
         if AlarmAddViewController.isVibration{
             AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate))
         }

        if let err = error {
            println("audioPlayer error \(err.localizedDescription)")
        } else {
            audioPlayer?.delegate = self
            audioPlayer?.prepareToPlay()
        }
        audioPlayer?.play()
        
        
        
        
        
    }
    
    
    func vibrationCallback(id:SystemSoundID, _ c:UnsafeMutablePointer<Void>) -> Void
    {
        print("callback")
    }

    
    func audioPlayerEndInterruption(player: AVAudioPlayer!) {
    }
    
    
    
    

    func applicationWillResignActive(application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
