【发布时间】:2015-10-15 08:49:23
【问题描述】:
我已经注册了Urban Airship,获得了app key、secret和master secret。我也集成了他们的库。
-(void)setupUrbanAirship
{
UAConfig *config = [UAConfig defaultConfig];
config.detectProvisioningMode = YES;
config.productionLogLevel=NO;
config.inProduction = NO;
config.developmentAppKey = @"XXXXXXXXXXXXXXXXXXX";
config.developmentAppSecret = @"XXXXXXXXXXXXXXXXX";
[UAirship takeOff:config];
[UAirship push].userPushNotificationsEnabled = YES;
[UAirship push].userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
}
我在我的代码中调用它:
NSString *channelID = [UAirship push].channelID;
NSLog(@"channelID %@",channelID);
在应用程序的第一次运行期间,channelID 始终为空。
我能够在第二次运行期间接收到 channelID,但在第一次运行期间无法接收。无论如何都可以建议应用程序在第一次运行期间获取 channelID 的方法。提前致谢。
已编辑:
根据 ralepinski 的建议,我正在添加 '[UAirship push].registrationDelegate = self.registrationDelegate' 行代码。
在 ViewController.h 中:
@interface ViewController : UIViewController
{
IBOutlet UIButton *selectButton;
NSTimer *channelIDDetectionTimer;
}
@property (nonatomic, weak, nullable) id<UARegistrationDelegate> registrationDelegate;
在 ViewController.m 中我也在使用这些代码行:
-(void)initRegistration
{
AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
NSString *channelID = [UAirship push].channelID;
NSLog(@"channelID %@",channelID);
if (channelID!=nil)
{
[delegate saveChannelID];
if (channelIDDetectionTimer!=nil)
{
[channelIDDetectionTimer invalidate];
channelIDDetectionTimer = nil;
}
}
else
{
[UAirship push].registrationDelegate = self.registrationDelegate;
//[[UAPush alloc]updateRegistration];
// Registering for only UIRemoteNotificationTypeNone will not result in a
// device token registration call. Instead update chanel registration directly.
}
}
-(void)viewWillAppear:(BOOL)animated
{
channelIDDetectionTimer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(initRegistration) userInfo:nil repeats:YES];
}
我在应用目标的功能部分启用了远程通知。在应用程序的第一次运行期间,我仍然将 ChannelID 设为 null。让我知道。谢谢。
【问题讨论】:
标签: ios urbanairship.com devicetoken