【问题标题】:Device Token incorrect with Urban Airship?城市飞艇的设备令牌不正确?
【发布时间】:2012-03-28 08:59:35
【问题描述】:

我正在尝试在我的应用中实现推送通知。所以,为了测试,我建立了一个新的应用程序并完成了所有必要的步骤(我希望......)。我在我的项目中添加了以下内容:

-AirshipConfig.plist
-libUAirship-1.1.4.a
-UAGLobal.
-UAirship.h
-UAObservable.h
-UAPush.h

以及他们网站上列出的所有框架。

我的 AppDelegate.m 是:

#import "AppDelegate.h"
#import "UAirship.h"
#import "UAPush.h"

@implementation AppDelegate

@synthesize window = _window;

-(void)setupPushWithOptions:(NSDictionary *)launchOptions {


//URBAN AIRSHIP PUSH NOTIFICATION CONFIGURATION
//Init Airship launch options
NSMutableDictionary *airshipConfigOptions = [[NSMutableDictionary alloc] init];
//[airshipConfigOptions setValue:@"5QQmJyTMRZWks0nbx-9pHQ" forKey:@"DEVELOPMENT_APP_KEY"];
//[airshipConfigOptions setValue:@"OMuzzHdCQOCnrOtfiWox9Q" 
forKey:@"DEVELOPMENT_APP_SECRET"];
[airshipConfigOptions setValue:@"xrUoy0B1RdyjZqZXEuwIsg" forKey:@"PRODUCTION_APP_KEY"];
[airshipConfigOptions setValue:@"qiRlUvoaSHGNeXxw9pj71w" forKey:@"PRODUCTION_APP_SECRET"];

#ifdef DEBUG
[airshipConfigOptions setValue:@"NO" forKey:@"APP_STORE_OR_AD_HOC_BUILD"];
#else
[airshipConfigOptions setValue:@"YES" forKey:@"APP_STORE_OR_AD_HOC_BUILD"];
#endif

NSMutableDictionary *takeOffOptions = [[NSMutableDictionary alloc] init];
[takeOffOptions setValue:launchOptions forKey:UAirshipTakeOffOptionsLaunchOptionsKey];
[takeOffOptions setValue:airshipConfigOptions 
forKey:UAirshipTakeOffOptionsAirshipConfigKey];    

// Create Airship singleton that's used to talk to Urban Airship servers.
// Please replace these with your info from http://go.urbanairship.com
[UAirship takeOff:takeOffOptions];

[[UAPush shared] resetBadge];//zero badge on startup    
[[UAPush shared] 
registerForRemoteNotificationTypes:UIRemoteNotificationTypeNewsstandContentAvailability|UIRemoteNotificationTypeAlert]; // register for Newsstand and Alerts

}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
//Init Airship launch options
NSMutableDictionary *takeOffOptions = [[NSMutableDictionary alloc] init];
[takeOffOptions setValue:launchOptions forKey:UAirshipTakeOffOptionsLaunchOptionsKey];

// Create Airship singleton that's used to talk to Urban Airship servers.
// Please populate AirshipConfig.plist with your info from http://go.urbanairship.com
[UAirship takeOff:takeOffOptions];
[[UIApplication sharedApplication]
 registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                     UIRemoteNotificationTypeSound |
                                     UIRemoteNotificationTypeAlert)];
// Override point for customization after application launch.

[self setupPushWithOptions:launchOptions];
return YES;
}

- (void)application:(UIApplication *)application  
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
UALOG(@"APN device token: %@", deviceToken);
 NSLog(@"%@", deviceToken);
// Updates the device token and registers the token with UA
[[UAirship shared] registerDeviceToken:deviceToken];
}

- (void)applicationWillResignActive:(UIApplication *)application
{
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
}

- (void)applicationWillTerminate:(UIApplication *)application
{
}

-(void)application:(UIApplication *)application  
didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"Failing in APNS registration: %@",error);
}

@end

这样我得到错误 Apple Push service denied device token 但我也发现我的设备令牌可能无法正确检索。根据 UA 工作人员的建议,我从 Appstore 下载了 App Wide Angle,并在连接 iPhone 并打开 Xcode 控制台的情况下启动了它。所以我可以看到我的设备令牌是另一个……问题出在哪里?

【问题讨论】:

    标签: ios xcode push urbanairship.com


    【解决方案1】:

    您不应该像这样将变量硬编码到 Urban Airship 中。

    创建 AirshipConfig.plist 该库使用 .plist 配置 名为 AirshipConfig.plist 的文件来管理您的生产和 开发应用程序配置文件。

    在您的 Urban Airship 帐户中创建 2 个应用程序 - 一个用于 开发和另一个用于生产。前任。 Name_of_your_app_dev Name_of_your_app_prod 创建一个 AirshipConfig.plist 文件 设置 将值添加到您的应用程序中的值

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多