gpt4 book ai didi

ios - Urbanairship 代表不工作

转载 作者:行者123 更新时间:2023-11-29 11:58:13 24 4
gpt4 key购买 nike

我在我的 iOS 应用程序中使用 UrbanAirship 处理推送通知。我想实现 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);
}

但是当我收到推送时,没有调用任何函数。我哪里做错了?

最佳答案

UAPush 仅存储对委托(delegate)的弱引用。您需要在代码中的某处存储强引用。

例子:

@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;
}

关于ios - Urbanairship 代表不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38203316/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com