1
我試圖在我的應用程序中實現推送通知。所以,爲了測試,我建立了一個新的應用程序,並完成了所有必要的步驟(我希望...)。我在我的項目中添加了以下內容:設備令牌與城市飛艇不符?
-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推送服務拒絕設備令牌 但我也想通了,我的設備令牌不能正確地檢索。遵循UA成員職員的建議,我從Appstore下載了App Wide,然後在iPhone連接並打開Xcode控制檯的情況下啓動它。所以我可以看到我的設備令牌是另一個......問題在哪裏?