1

저는 iOS App에서 푸시 알림을 처리하기 위해 UrbanAirship을 사용하고 있습니다. UAPushNotificationDelegate 구현하고 싶습니다. 여기 appdelegate 내 코드입니다.Urbanairship 대리인이 작동하지 않습니다.

//Appdelegate.m 
UAConfig *config = [UAConfig defaultConfig]; 
[UAirship takeOff:config]; 

[[UAirship push] updateRegistration]; 
[UAirship push].userNotificationTypes = (UIUserNotificationTypeAlert | 
             UIUserNotificationTypeBadge | 
             UIUserNotificationTypeSound); 

[UAirship push].autobadgeEnabled = YES; 
[UAirship push].userPushNotificationsEnabled = YES; 
PushHandler *pushHandlerDelegate = [[PushHandler alloc] init]; 
[UAirship push].pushNotificationDelegate = pushHandlerDelegate; 

여기 내 PushHandler.h 파일

// PushHandler.h 
@interface PushHandler : NSObject<UAPushNotificationDelegate> 

@end 

가 그럼 난 내 구현 파일

- (void)receivedForegroundNotification:(NSDictionary *)notification fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { 
// Call the completion handler 
    completionHandler(UIBackgroundFetchResultNoData); 
} 
- (void)launchedFromNotification:(NSDictionary *)notification fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{ 
// Call the completion handler 
    completionHandler(UIBackgroundFetchResultNoData); 
} 

- (void)launchedFromNotification:(NSDictionary *)notification actionIdentifier:(NSString *)identifier completionHandler:(void (^)())completionHandler { 
// Call the completion handler 
    completionHandler() 
} 

- (void)receivedBackgroundNotification:(NSDictionary *)notification actionIdentifier:(NSString *)identifier completionHandler:(void (^)())completionHandler { 
// Call the completion handler 
    completionHandler() 
} 

- (void)receivedBackgroundNotification:(NSDictionary *)notification fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { 
// Call the completion handler 
    completionHandler(UIBackgroundFetchResultNoData); 
} 

에 UrbanAirship 방법을 구현하지만 푸시를받을 때 기능의 비 호출하는 것입니다. 내가 어디에서 잘못하고 있니?

+0

안녕하세요. 해결책을 찾았습니까? –

답변

1

UAPush는 위임자에 대한 약한 참조 만 저장합니다. 코드의 어딘가에 강력한 참조를 저장해야합니다.

예 :

@interface AppDelegate() 
@property(nonatomic, strong) PushHandler *pushHandlerDelegate; 
@end 

@implementation AppDelegate 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    ... 

    self.pushHandlerDelegate = [[PushHandler alloc] init]; 
    [UAirship push].pushNotificationDelegate = self.pushHandlerDelegate; 
} 
+1

안녕하세요. 답변을 주셔서 감사합니다. 그러나 전 여전히 포 그라운드 알림에만 액세스 할 수 있습니다. 앱이 백그라운드에있을 때 푸시를받을 수는 없지만 푸시는 수신 중이지만 "receivedBackgroundNotification :"메소드는 실행되지 않습니다. –

+0

APNS는 콘텐츠 사용 가능 푸시를 보내고 백그라운드 원격 알림이 사용 설정된 경우에만 앱을 작동시킵니다. 또한 백그라운드 새로 고침이 활성화되어 있고 작업 전환기를 통해 앱을 종료하지 않았는지 확인하십시오. – ralepinski

관련 문제