【问题标题】:UrbanAirship pushNotificationDelegate never get calledUrbanAirship pushNotificationDelegate 永远不会被调用
【发布时间】:2014-03-17 10:30:19
【问题描述】:

我正在使用 UrbanAirship 来管理我的 iOS 应用程序中的通知。 我想添加一些关于如何管理通知的特定行为,因此我决定在自定义处理程序上实现协议UAPushNotificationDelegate

在这个协议中,我只是在这两个函数中添加了一些用于测试目的的 NSLog。

- (void)displayNotificationAlert:(NSString *)alertMessage{
    NSLog(@"Foreground Alert");
}

- (void)launchedFromNotification:(NSDictionary *)notification{
   ....Here I added code to present an alert view...
}

然后在 AppDelegate 方法 didFinishLaunchingWithOptions 我添加了 UrbanAirship 配置:

// UrbanAirship data
UAConfig *config = [UAConfig defaultConfig];
[UAirship takeOff:config];

// THE DELEGATE!
UANotificationDelegate *pushDelegate = [[UANotificationDelegate alloc]init];
[UAPush shared].pushNotificationDelegate = pushDelegate;

[UAPush shared].notificationTypes = (UIRemoteNotificationTypeBadge |
                                     UIRemoteNotificationTypeSound |
                                     UIRemoteNotificationTypeAlert );

这是我用来测试代码的测试 curl 调用。

   curl -X POST -u "_APPKEY_:_MASTERKEY_" \
   -H "Content-Type: application/json" \
   --data '{"device_tokens": ["_THETOKEN_"], 
   "aps": {"alert": "Hello!"}}' \
   https://go.urbanairship.com/api/push/

我的设备收到通知,但我的自定义方法永远不会被调用。 我做错了什么?

【问题讨论】:

    标签: ios urbanairship.com


    【解决方案1】:

    pushNotificationDelegate 属性很弱,所以没有什么可以阻止您的 pushDelegate 被垃圾收集。您需要自己将 pushDelegate 变量存储在某个地方,以确保它不会被释放。

    【讨论】:

      猜你喜欢
      • 2012-10-27
      • 2013-10-12
      • 2012-03-27
      • 2013-08-29
      • 2013-11-03
      • 1970-01-01
      • 1970-01-01
      • 2015-05-06
      • 2015-10-15
      相关资源
      最近更新 更多