جدولة UilocalNotification مع تكرار لعدد الساعة 10 صباحًا بتوقيت جرينتش

StackOverflow https://stackoverflow.com/questions/4603253

سؤال

أنا آسف إذا كان هذا سؤالًا مطلقًا ، لكن لا يمكنني معرفة ذلك من الوثائق أو أسئلة المكدس الأخرى -

كيف يمكنني ضبط كائن NSDATE إلى الساعة 10:00 صباحًا بتوقيت جرينتش؟ السبب في أنني أطلب هذا - أريد أن أحدد تحديدًا محليًا في الساعة 10:00 صباحًا بتوقيت جرينتش كل يوم.

أعتقد أن ما يلي على المسار الصحيح:

    NSDateComponents *comps = [[NSDateComponents alloc]init];
[comps setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];

[comps setYear:2011];
[comps setMonth:1];
[comps setWeek:1];
[comps setDay:1];
[comps setHour:10];
[comps setMinute:52];
[comps setSecond:0];

NSCalendar *gregorian = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];

NSDate *date = [gregorian dateFromComponents:comps];
[comps release];

UILocalNotification *notif = [[UILocalNotification alloc]init];

notif.fireDate = date;
notif.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];
notif.alertBody = @"New Challenges are available in Halo: Reach.\n\n Give them a look over with Halo Reach Challenges!";
notif.alertAction = @"Show Me";
notif.applicationIconBadgeNumber = 5;
notif.repeatInterval = NSDayCalendarUnit;

[[UIApplication sharedApplication] scheduleLocalNotification:notif];
[notif release];

لسوء الحظ ، هذا لا يطلق النار. أي مساعدة سيكون موضع تقدير كبير :)

هل كانت مفيدة؟

المحلول

طالما أن تطبيقك يعمل ، يتم إرسال الإشعار مباشرة إلى تطبيقك. ستحتاج إلى إعداد معالج (في AppDelegate) وعرض الرسالة بنفسك. عندما لا يتم تشغيل التطبيق ، يجب عرض الإشعار.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top