2010-09-03 5 views
2

Dans mon application universelle, j'utilise le code ci-dessous pour UILocalNotificationcomment utiliser UILocationNotification dans iPad?

NSCalendar * calendar = [NSCalendar autoupdatingCurrentCalendar];

// Get the current date 
    NSDate *pickerDate = [self.datePicker date]; 

    // Break the date up into components 
    NSDateComponents *dateComponents = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) 
                fromDate:pickerDate]; 
    NSDateComponents *timeComponents = [calendar components:(NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) 
                fromDate:pickerDate]; 

    // Set up the fire time 
    NSDateComponents *dateComps = [[NSDateComponents alloc] init]; 
    [dateComps setDay:[dateComponents day]]; 
    [dateComps setMonth:[dateComponents month]]; 
    [dateComps setYear:[dateComponents year]]; 
    [dateComps setHour:[timeComponents hour]]; 
    // Notification will fire in one minute 
    [dateComps setMinute:[timeComponents minute]]; 
    [dateComps setSecond:[timeComponents second]]; 
    NSDate *itemDate = [calendar dateFromComponents:dateComps]; 
    [dateComps release]; 

    UILocalNotification *localNotif = [[UILocalNotification alloc] init]; 
    if (localNotif == nil) 
     return; 
    localNotif.fireDate = itemDate; 
    localNotif.timeZone = [NSTimeZone defaultTimeZone]; 

    // Notification details 
    NSString *str = [txtfield_MyPills.text stringByAppendingString:@" "]; 
    NSString *str_Dosage = [txtfield_Dosage.text stringByAppendingString:@" "]; 
    NSString *str_Frequency = [txtfield_Frequency.text stringByAppendingString:@" "]; 
    NSString *str1 = [str stringByAppendingString:str_Dosage]; 
    NSString *strResult = [str1 stringByAppendingString:str_Frequency]; 
    localNotif.alertBody =strResult;;// [txtfield_MyPills text];//[eventText text]; 
    // Set the action button 
    localNotif.alertAction = @"View"; 


    localNotif.soundName = UILocalNotificationDefaultSoundName; 
    localNotif.applicationIconBadgeNumber = 1; 

    // Specify custom data for the notification 
    NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"someValue" forKey:@"someKey"]; 
    localNotif.userInfo = infoDict; 

    // Schedule the notification 
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif]; 
    [localNotif release]; 

Son workin bien dans iphone mais si je lance mon application pour iPad, il montre que UilOcation est non déclaré?

S'il vous plaît, aidez-moi et si u ont exemple de code pour UILocalNotification pour iPad s'il vous plaît donner le lien pour que

Merci à l'avance

Répondre

0

Comme Aron a dit que les Uiloaclnotifications ne sont pas disponibles dans 3.2.
Comme vous le savez, la nouvelle version d'iOs pour iPad arrive très bientôt. Asoming que cela prendra du temps jusqu'à ce que tous les utilisateurs de mise à niveau, vous pouvez le faire -

Essayez this-

classe notifs = (NSClassFromString (@ "UILocalNotification));

Si (notifs = nul!) {

// le code de notification ici }

J'ai été informé par le soutien aux pommes que vous pouvez tester que seulement sur des appareils réels qui fonctionnent 3.2 et non sur le simulateur.

Vous pouvez regarder ici dans l'exemple de code postal compositeur chez Apple pour voir comment ils mis en œuvre que:

https://developer.apple.com/iphone/library/iPad/index.html#samplecode/MailComposer/Listings/Classes_MailComposerViewController_m.html

espère que cela aidera Shani

Questions connexes