로컬 알림을 설정했습니다. 해고 당하면 내 앱이 집 버튼을 눌렀을 때 "잠자기"모드에 있다고 말하거나 종료합니다. 이제 알림이 수신됩니다. 내 앱에 빨간색 태그가 표시되고 앱을 클릭하면 didReceiveLocalNotification
을 실행해야하지만 그렇지 않습니다. 앱을 열 때 어떻게 할 수 있습니까?로컬 알림 앱이 열릴 때 표시되지 않음
답변
didReceiveLocalNotification
메서드는 응용 프로그램이 포 그라운드에서 실행될 때만 호출됩니다. 배지를보고 앱을 클릭하여 시작하면 application:willFinishLaunchingWithOptions:
(또는 application:didFinishLaunchingWithOptions:
)을 사용하여 로컬 알림을 처리해야합니다. 두 가지 방법 중 하나에서 로컬 알림을 받으려면 UIApplicationLaunchOptionsLocalNotificationKey
을 옵션 사전의 키로 사용하십시오 .
UILocalNotification 문서에서 [편집] :
로컬 알림은 응용 프로그램 아이콘 배지 및 응답의 사용자가 응용 프로그램의 응용 프로그램을 실행하는 경우 : didFinishLaunchingWithOptions를 : 메소드가 호출,하지만 UILocalNotification 개체가 옵션 사전에 포함되어 있습니다.
-(void)alarmNotification
{
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
NSDate *newdate = timePicker.date;
NSLog(@"pickerdate:%@",newdate);
NSDate *pickerDate =[newdate dateByAddingTimeInterval:-60*1];
NSLog(@"pickerdate:%@",timePicker.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];
localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
localNotif.fireDate = itemDate;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
// Notification details
localNotif.alertBody = txtMeetingName.text;
// Set the action button
localNotif.alertAction = NSLocalizedString(@"View!", nil);
localNotif.soundName = UILocalNotificationDefaultSoundName;
// Specify custom data for the notification
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"someValue" forKey:@"someKey"];
localNotif.userInfo = infoDict;
localNotif.applicationIconBadgeNumber =1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}
그런
didLinunchOptions에서 가져오고 싶습니다. didReceive와 잘 작동합니다. 사실 앱이 닫히고 정상적으로 열리면 푸시 알림과 달리 launchOptons에 나타나지 않습니다 –
당신이 화재 날짜를 설정하는 경우 다음이 가지고 ......이 당신을 도울 것입니다
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
// Handle the notificaton when the app is running
NSDateComponents *comps = [[NSCalendar currentCalendar] components:notif.repeatInterval fromDate:notif.fireDate toDate:[NSDate date] options:0];
// you can set your own sound
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/win.wav", [[NSBundle mainBundle] resourcePath]]];
NSError *error;
UIAlertView *alertView =
[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"move on", nil)
message:[NSString stringWithFormat:@"You have to start %@ meeting within 5 minute",notif.alertBody]
delegate:self
cancelButtonTitle:nil
otherButtonTitles:NSLocalizedString(@"OK", nil), nil];
notif.soundName = UILocalNotificationDefaultSoundName;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
audioPlayer.numberOfLoops = -1;
if (audioPlayer == nil)
NSLog(@"error%@",[error description]);
else
[audioPlayer play];
[alertView show];
[alertView release];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex: (NSInteger)buttonIndex{
if (buttonIndex==0) {
[audioPlayer stop];
}
NSLog(@"U HAVE CLICKED BUTTON");
}
희망을 .....이 코드를 구현 알림 개체의 userInfo 속성을 설정 하시겠습니까 ??? & 기기 또는 시뮬레이터에서 확인 하시겠습니까 ??
- 1. GCM Android 알림 앱이 열릴 때 알림
- 2. 앱이 열릴 때 푸시 알림이 작동하지 않습니다.
- 3. 알림 센터에 일부 기기에 앱이 표시되지 않음
- 4. 앱이 이미 실행 중일 때 로컬 알림 소리가 들리지 않음
- 5. 앱이 열릴 때 알림을 감지하는 방법
- 6. 갤러리에 앱이 표시되지 않음
- 7. 알림 수신되었지만 표시되지 않음
- 8. Spinner 앱이 열릴 때 충돌이 발생합니다.
- 9. iOS 앱이 다시 열릴 때 오류가 발생합니다.
- 10. 앱이 4 번 열릴 때 종료되었습니다.
- 11. 아이폰 앱이 열릴 때 이전 상태를 보여줍니다.
- 12. 앱이 열릴 때 통화 기능이 활성화됩니다.
- 13. 앱이 꺼져있을 때 알림
- 14. 푸시 기능이 설정된 앱이 기기의 알림 섹션에 표시되지 않음
- 15. didEnterRegion의 단일 로컬 알림
- 16. Android 앱이 에뮬레이터에 표시되지 않음
- 17. 앱이 cordova에서 실행 중일 때 알림이 표시되지 않음
- 18. `willPresent notification`이 호출되지 않고 iOS 10에서 앱이 포 그라운드에있을 때 로컬 알림이 표시되지 않음
- 19. 푸시 알림 배너가 표시되지 않음 - ios9
- 20. 앱이 2.1 시장에 표시되지 않음
- 21. 앱이 Google Play에 표시되지 않음
- 22. facebook 앱이 표시되지 않음 https
- 23. 장치에 아이폰 앱이 제대로 표시되지 않음
- 24. 로컬 알림 취소 작동하지 않음
- 25. jQuery 알림, 처음 표시되지 않음
- 26. 앱이 iPhone에서 열려있을 때 알림 센터에만 로컬 알림이 표시됩니다.
- 27. 앱이 배경에있을 때 알림 센터에 UILocalNotification이 표시되지 않습니다.
- 28. 푸시 알림 앱이 백그라운드 일 때 FCM이 표시되지 않습니다.
- 29. 앱이 실행 중이 아닐 때 실행되지만 앱이 실행 중일 때 계속 알림 알림 처리
- 30. blackberry - applicationMessage가 열릴 때 청취합니다.
시작 옵션이 nil을 반환합니다 ..... 알림 표시 줄에 알림을 볼 수 있지만 실행 옵션이 응용 프로그램을 열 때 nil을 반환합니다 –
launchOptions 사전이 nil입니까? 그렇지 않다면 그 내용은 무엇입니까? – GoZoner
틀렸어. 그것은 없습니다. 그것은 뭔가를 반환해야합니다. didEnterBackground에 간단한 알림을 넣으려고했습니다. 열린 된 응용 프로그램, 홈 버튼을 눌렀습니다. Xcode를 사용하여 응용 프로그램을 종료 한 다음 알림을받은 후 Xcode를 사용하여 다시 테스트하십시오. 아직도 없다. –