0

我正在开发支持 playerduel 框架的应用程序。在其中两个玩家可以互相玩。人可以向另一个人发送挑战。我遵循以下文档。 https://docs.urbanairship.com/display/DOCS/Getting+Started%3A+iOS%3A+Push

当我从命令行(用于测试)发送通知时,我可以收到通知,如上述文档中所述。但是我玩游戏的时候。当有人向另一人发送挑战时,Playerdual 无法发送通知。

应用程序代码:-

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

//Init Airship launch options
NSMutableDictionary *takeOffOptions = [[[NSMutableDictionary alloc] init] autorelease];
[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];

// Register for notifications
[[UAPush shared]registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                     UIRemoteNotificationTypeSound |
                                     UIRemoteNotificationTypeAlert)];

// Override point for customization after application launch.
self.appStarted  = YES;
UIImage *bgImage= [UIImage imageNamed:@"default.png"];
[PlayerDuel initializeWithGameKey:@"gamekey" andBackground:bgImage
                      andDelegate:[navigationController.viewControllers objectAtIndex:0] andOrientation:UIInterfaceOrientationPortrait];


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

}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

for (id key in userInfo) {
    NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]);
}    

NSLog(@"remote notification: %@",[userInfo description]);

NSDictionary *apsInfo = [userInfo objectForKey:@"aps"];



NSString *alert = [apsInfo objectForKey:@"alert"];

NSLog(@"Received Push Alert: %@", alert);



NSString *sound = [apsInfo objectForKey:@"sound"];

NSLog(@"Received Push Sound: %@", sound);
NSString *itemName = @"my app";
NSString *messageTitle = [apsInfo objectForKey:@"alert"];
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive){
    AudioServicesPlaySystemSound(1007);
 [self _showAlert:messageTitle withTitle:itemName];
}
else{
    UIViewController *viewController = navigationController.visibleViewController;
    //        NSLog(@"Controller Name:-  %@",viewController);
    [viewController.view reloadInputViews];
    [viewController playerDuelStartGame:nil];
}
NSString *badge = [apsInfo objectForKey:@"badge"];

NSLog(@"Received Push Badge: %@", badge);

}

4

2 回答 2

2

如果推送通知直接通过 Urban Airship 而不是通过 PlayerDuel 工作,您可能没有在 PlayerDuel 的开发者网站中指定正确的城市飞艇详细信息。确保将 Urban Airship 的 Master Secret 而不是 App Secret 放在 PlayerDuel 的网站上。

于 2012-09-12T08:31:11.713 回答
0

我使用 App Secrete 作为 Urban Airship Key: . 这是错误的。当我将其值更改为 App Key 时。它工作正常。

于 2012-09-12T13:38:21.547 回答