2015-02-04 3 views
1

나는 목표 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

응용 프로그램 아이콘을 배지 시도 모두 OS

답변

0

아래라고하지만, 응용 프로그램

를 배지하기 위해 사용자의 허가를받지 못한 엑스 코드는 당신이 할 수 있음을 알려주는 방법입니다 시뮬레이터에서 실행되는 동안 알림 배지 값을 변경하지 마십시오. 허용되지 않음

iOS가 결정할 때이 위임 메서드가 호출됩니다. UIApplicationDelegate 문서에서 :

데이터를 다운로드 할 수있는 기회가 생기면 시스템에서이 메서드를 호출하여 필요한 모든 데이터를 다운로드 할 수 있습니다. 더 중요한 것은 시스템이 경과 시간을 사용하여 앱의 백그라운드 다운로드에 대한 전력 사용량과 데이터 비용을 계산한다는 것입니다. 앱이 완료 핸들러를 호출하는 데 시간이 오래 걸리는 경우 향후 데이터를 가져올 기회가 줄어들 수 있습니다.

+0

나는 이해하지만 performFetchWithCompletionHandler에서 로그 메시지를 얻지 만 7.1에서 fetchnotification을 호출하지는 않지만 8.1에서 않습니다. – Marc

관련 문제