2013-07-22 30 views
1

是否可以設置一個應用程序在指定的時間發送自己的通知?也許把他們放在隊列中?到目前爲止,我不得不通過一個推送通知服務器,當我每週二早上發送消息時,這看起來像是在殺人。此外,這是什麼所謂的(這樣我就可以更好地研究它在網絡上)有預謀的通知

+5

UILocalNotification應該是一個開始! – Moxy

+1

因此,您希望您的應用只在每個星期二的早上8:00彈出消息?當用戶不在應用中時,這是否會彈出? – MZimmerman6

回答

3

可以安排通知如下:

- (void)scheduleNotification 
{ 
    //Cancel all previous Local Notifications 
    [[UIApplication sharedApplication] cancelAllLocalNotifications]; 

    //Set new Local Notifications 
    Class cls = NSClassFromString(@"UILocalNotification"); 
    if (cls != nil) 
    { 
     UILocalNotification *notif = [[cls alloc] init]; 
     //3 days 
     notif.fireDate = [NSDate dateWithTimeInterval:60.0f*60.0f*24.0f*3.0f sinceDate:[NSDate date]]; 
     notif.timeZone = [NSTimeZone defaultTimeZone]; 
     notif.alertBody = @"Come Back Again! Lets blast All Zombie!"; 
     notif.alertAction = @"PLAY"; 
     notif.soundName = UILocalNotificationDefaultSoundName; 
     notif.applicationIconBadgeNumber = 1; 
     [[UIApplication sharedApplication] scheduleLocalNotification:notif]; 
     }  
} 


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    [application registerForRemoteNotificationTypes: 
    UIRemoteNotificationTypeBadge | 
    UIRemoteNotificationTypeAlert | 
    UIRemoteNotificationTypeSound]; 

    [self scheduleNotification]; 
    .. 
}