오전 9시에 사용자에게 일일 알림을 제공하는 앱을 만들었지 만 원할 경우 사용자가 해제 할 수있게하려고합니다.사용자가 로컬 알림을 비활성화 할 수 있습니까?
나는 앱에 대한 설정 번들을 설정하고 enableNotifications에 대한 슬라이더를 설정했습니다. 내가 빌드하고 응용 프로그램을 테스트 할 때, 설정이 거기에 있고 그들을 켜거나 끌 수 있습니다 ...하지만 그것은 응용 프로그램에 그것을 등록하는 것 같습니다. 알림 설정이 켜져 있거나 꺼져 있는지 여부를 확인하기 위해 앱을 프로그래밍하려면 어떻게해야합니까?
나는이 대답했다 : Determine on iPhone if user has enabled push notifications 을하지만 난에 넣어 위치를 잘 모릅니다 프로그램이 제대로 (/ else 문 등의 경우) 다음알림이 생성 된 코드 :
-(id) getCommandInstance:(NSString*)className
{
/** You can catch your own commands here, if you wanted to extend the gap: protocol, or add your
* own app specific protocol to it. -jm
**/
[[UIApplication sharedApplication] cancelAllLocalNotifications];
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
NSCalendar *calender = [NSCalendar autoupdatingCurrentCalendar];
NSDate *currentDate = [NSDate date];
NSDateComponents *dateComponents = [calender components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit)
fromDate:currentDate];
NSDateComponents *temp = [[NSDateComponents alloc]init];
[temp setYear:[dateComponents year]];
[temp setMonth:[dateComponents month]];
[temp setDay:[dateComponents day]];
[temp setHour: 22];
[temp setMinute:00];
NSDate *fireTime = [calender dateFromComponents:temp];
[temp release];
// set up the notifier
UILocalNotification *localNotification = [[UILocalNotification alloc]init];
localNotification.fireDate = fireTime;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.alertBody = @"Don't Forget Your 365 Day Photo Challenge!";
localNotification.alertAction = @"LAUNCH";
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.repeatInterval = NSDayCalendarUnit;
localNotification.applicationIconBadgeNumber = 0;
[[UIApplication sharedApplication]scheduleLocalNotification:localNotification];
[localNotification release];
return [super getCommandInstance:className];
}
은 당신은 단지 하나의 localNotification이 그것을 취소하려면
추가 연구를 통해 나는 내가해야 할 일이라고 생각했다. http://useyourloaf.com/blog/2010/05/18/adding-a-settings-bundle-to-an-iphone -app.html 그러나,이 코드에서 변경 모르겠어요 : - (BOOL) shouldAutorotateToInterfaceOrientation : (UIInterfaceOrientation) interfaceOrientation { // 사용자 환경 설정을 가져 NSUserDefaults * 기본값 = NSUserDefaults standardUserDefaults] BOOL enabled = [기본값 boolForKey : @ "enableRotation"]; if (enabled) { return YES; } else { return (interfaceOrientation == UIInterfaceOrientationPortrait); } } –