1

我正在使用UrbanAhiphip处理iOS应用中的推送通知。我想实现UAPushNotificationDelegate。这是我在appdelegate的代码。不能使用的楼梯代表

//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 

然后我实现UrbanAirship方法我在执行文件

- (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); 
} 

但是,当我收到一个推送的功能不被调用。我在哪里做错了?

+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

嗨..谢谢你的回答,但我仍然只能访问前台通知。当应用程序处于后台时,我无法获得推送,Push正在接收,但它并未触发“receivedBackgroundNotification:”方法。 –

+0

如果您发送可用于内容的推送,并且启用了后台远程通知,则APNS只会将应用程序唤醒。同时确保后台刷新已启用,并且您没有通过任务切换器关闭应用程序。 – ralepinski