나는 목표 C로 알림을 보내려고하는데 어떻게해야하는지 알 수 없습니다. 나는 IOS 8.1 아이폰 6 시뮬레이터하려고하면로컬 알림을 보내는 방법
은 지금까지 나는
- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
if(self.username != nil)
{
NSLog(@"Background fetch username: %@", self.username);
[self fetchNotifications];
}
completionHandler(UIBackgroundFetchResultNewData);
}
- (void)fetchNotifications
{
NSURL *url = [NSURL URLWithString:
[NSString stringWithFormat:@"%@%@",
@"https://myurl?username="
, self.username]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response,
NSData *data, NSError *connectionError)
{
if (data.length > 0 && connectionError == nil)
{
NSDictionary *notifications = [NSJSONSerialization JSONObjectWithData:data
options:0
error:NULL];
int nbMessages = [[notifications objectForKey:@"NbOfUnreadMessage"] intValue];
int nbOfNewMatch = [[notifications objectForKey:@"NbOfNewMatch"] intValue];
int nbOfNewPlanification = [[notifications objectForKey:@"NbOfNewPlanification"] intValue];
//int nbMessages = [[notifications objectForKey:@"NbOfUnreadMessage"] intValue];
NSLog(@"Notifications - nbMessage: %i",nbMessages);
NSLog(@"Notifications - nbNewMatch: %i",nbOfNewMatch);
NSLog(@"Notifications - nbNewPlan: %i",nbOfNewPlanification);
// Schedule the notification
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = nil;
localNotification.alertBody = @"test";
localNotification.alertAction = @"Show me the item";
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}
}];
}
가 나는 다음과 같은 오류
응용 프로그램 아이콘을 배지 시도했지만 허가를받지 못한이 응용 프로그램을 배지 할 사용자
나는 이것을 읽고 이해해야 할 것이다. post
하지만 실제 문제는 iPhone 5 IOS 7.1 시뮬레이터를 사용할 때 함수 fetchNotifications
도 호출되지 않습니다.
왜 fetchNotifications
은 IOS 8.1에서만 필요합니까?
performFetchWithCompletionHandler
나는 이해하지만 performFetchWithCompletionHandler에서 로그 메시지를 얻지 만 7.1에서 fetchnotification을 호출하지는 않지만 8.1에서 않습니다. – Marc