我已经注册了Urban Airship,获得了应用程序密钥,密钥和主密钥。我也整合了他们的图书馆
-(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。告诉我谢谢
2条答案
按热度按时间3gtaxfhh1#
信道创建依赖于网络请求。它不会立即可用,但您可以使用UARegistrationDelegate侦听它何时可用。您可以在UAPush示例上分配委托:
有时,如果SDK无法生成deviceToken,通道注册会延迟到下一个应用前台。如果您在应用程序的功能部分中启用了远程通知,则将立即生成设备令牌,并在第一次运行时创建通道。
2j4z5cfb2#
在我的例子中,ChannelCreated事件在第一次午餐后3分钟被触发。只是必须非常耐心。
也许是苹果或Airship的API问题?
(我正在使用Airship和Expo以及React-Native)