簡體   English   中英

Apple Push Notifications:沒有收到設備令牌?

[英]Apple Push Notifications: Not receiving device token?

在涉及推送通知的應用程序中,我可以正常接收設備令牌,但是我的客戶端的設備無法接收設備令牌(因此導致無法接收推送通知)。 我正在使用Parse進行推送通知。 這就是我的AppDelegate

-(void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)newDeviceToken {
    // Store the deviceToken in the current installation and save it to Parse.
    PFInstallation *currentInstallation = [PFInstallation currentInstallation];
    [currentInstallation setDeviceTokenFromData:newDeviceToken];
    PFACL *objectACL = [[PFACL alloc] init];
    [objectACL setPublicReadAccess:YES];
    [objectACL setPublicWriteAccess:YES];

    [currentInstallation saveInBackground];
}

-(void) application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{

    NSString *errorString = [NSString stringWithFormat:@"%@", error];
    UIAlertView *errorAlertView = [[UIAlertView alloc] initWithTitle:@"Error" message:errorString delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];

    [errorAlertView show];
}
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
    [application registerForRemoteNotifications];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    [Parse setApplicationId:PARSE_APPLICATION_ID
                  clientKey:PARSE_CUSTOMER_KEY];
    [PFFacebookUtils initializeFacebook];

    [self.window makeKeyAndVisible];

    // create the Login controller instance:

    [application registerForRemoteNotificationTypes:
     UIRemoteNotificationTypeBadge |
     UIRemoteNotificationTypeAlert |
     UIRemoteNotificationTypeSound];
}

客戶端未收到任何表示未向APN注冊失敗的UIAlert,因此這意味着未調用didFailToRegisterForRemoteNotificationsWithError 我已嘗試按照Apple技術說明TN2265的指導從我的解析服務器中刪除所有安裝,刪除該應用程序並重新安裝。 該應用程序不會在第一次啟動時提示客戶端授權推送通知,也不會出現在通知中心(這令人困惑,因為didRegisterUserNotificationSettings:也存在)。 但這一切在我的iPad,iPhone 5S,iPod 5,iPhone 4s上都可以正常工作。 任何想法可能導致此設備在應用程序中發生設備變量行為嗎?這是sc客戶端發送給我的。 notificationCenterScreenShot

嘗試以下代碼

    if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)])
    {
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    }
    else
    {
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
         (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
    }

內部- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions類中的- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM