2012-08-24 2 views
2

오전 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이 그것을 취소하려면
+0

추가 연구를 통해 나는 내가해야 할 일이라고 생각했다. 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); } } –

답변

0

설명을 바탕으로, 앱의 환경 설정 (알림 사용 여부)에서 알림 설정의 값을 가져 오는 방법을 묻는 것 같습니다.

[NSUserDefaults standardUserDefaults]를 사용하여 기본 설정 값에 액세스해야합니다. 이 Accessing Preference Values 문서를 참조하십시오.

+0

둘 다 감사합니다! 나는이 방법을 설정 할 수 있었다 : ([[NSUserDefaults standardUserDefaults] boolForKey : @ "enableNotifications은"]) 경우 다른 {[[UIApplication sharedApplication] cancelAllLocalNotifications];} { 코드는 알림을 사용하려면} \t 반환 [super getCommandInstance : className]; } –

1

당신은 단지 호출 할 수 있습니다 : '이 때로 믿을 경우

[[UIApplication sharedApplication] cancelAllLocalNotifications]; 

이 오류가 발생하지 않습니다 t 모든 localNotifications. IBAction 버튼을 눌러 호출 할 수 있습니다. 당신이 그것을보고 후 어떤 localNotifications이 있습니다 여부를 확인할 수 수에 따라 스위치의 상태를 설정하려면 어떤있다 :

NSArray* localNotifications = [[UIApplication sharedApplication] 
               scheduledLocalNotifications]; 

localNotifications.count> 0 다음 예약 된 약간의 통지가있는 경우.

+0

안녕하세요 SkinnyTOD 어떻게 IF/THEN 문으로 구현할 수 있습니까? –

+0

@ user1114118 : 질문을 이해할 수 없습니다. –

+0

죄송합니다. 내 코딩 지식은 매우 제한적입니다. 저의 이해가 필요합니다 : 1) 사용자가 설정 번들 에서 로컬 알림을 설정했는지 여부를 확인하십시오. 2) 알림이 설정되어있는 경우 알림을 설정하십시오. 3) 그렇지 않은 경우 아무 것도하지 않습니다. 코드에서 구현하기 위해 내가 무엇을해야하는지 모르겠습니다. –

관련 문제