2012-08-24 5 views
0

나는 목표 C에 익숙하지 않다. 푸시 알림을 구현해야하는 앱에서 새 앱 ID를 만들었고 새 프로비저닝 프로필도 만들었습니다. 이 모든 단계를 완료했습니다. link푸시 알림 위임 메서드 문제

내 appDelegate .m 파일에서이 위임 함수를 선언했습니다.

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { 

     NSString *deviceTokens = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]]; 
     deviceTokens = [deviceTokens stringByReplacingOccurrencesOfString:@" " withString:@""]; 
     NSLog(@"registered device token %@", deviceTokens); 
     self.deviceToken = deviceTokens; 
} 

- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err { 

    NSString *str = [NSString stringWithFormat: @"Error: %@", err]; 
    NSLog(@"String %@",str);  

} 

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { 

    for (id key in userInfo) { 
     NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]); 
    }  

} 

그러나이 대리인 함수는 호출되지 않습니다. 이 문제를 해결하도록 도와주세요. 옵션을 사용하여 AppDelegated didfinishLaunching에서

답변

3

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)]; 
0

경우 ([응용 프로그램 respondsToSelector 앱 위임 내부 응용 프로그램 didFinishLaunchingWithOptions 메소드에이 코드를 추가하여 다음 줄을 쓰기 : @selector (registerUserNotificationSettings :) ]) {

//We check because ios7 cannot respond to this method and there will be a crash.. 
    UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert; 

    UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:nil]; 

    [[UIApplication sharedApplication] registerUserNotificationSettings:mySettings]; 
    [application registerForRemoteNotifications]; 
} 
else { 
    //This will work on ios7 devices and below 
    UIRemoteNotificationType types = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound; 
    [application registerForRemoteNotificationTypes:types]; 
    [application registerForRemoteNotifications]; 
} 

return YES; 
+0

,하지만 응용 프로그램에서 registerForRemoteNotifications 메서드를 호출하는지 확인하십시오. 그렇지 않으면 registerForNotifications를 시도하지 않았기 때문에 푸시 알림 대리자 메서드에 충돌하지 않습니다. – Mthokozisi

0

를 사용하여 새 대리자 메서드

,

스위프트 : FUNC 응용 프로그램 (응용 프로그램 : UIApplication, didReceiveRemoteNotification 사용자 정보 : [NSObject의 : AnyObject, fetchCompletionHandler completionHandler : (UIBackgroundFetchResult) -> 무효) 나는 일을 코드 소스의 첫 부분을 얻는 방법을 잘 모릅니다