【发布时间】:2015-03-07 11:50:55
【问题描述】:
我正在开发一个带有推送通知的 iOS 应用程序,它在使用设备通过 xcode 运行时工作正常。但我尝试生成 ipa 并安装它不起作用。(从后端服务器发送通知,没有生成设备令牌ipa)。我用来注册推送通知的代码。
if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
{
// iOS 8 Notifications
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[application registerForRemoteNotifications];
}
else
{
// iOS < 8 Notifications
[application registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
}
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
NSString *tokenStr = [[[[deviceToken description]
stringByReplacingOccurrencesOfString:@"<" withString:@""]
stringByReplacingOccurrencesOfString:@">" withString:@""]
stringByReplacingOccurrencesOfString:@" " withString:@""];
NSLog(@"Device Token (raw): %@", deviceToken);
NSLog(@"Device Token (string): %@", tokenStr);
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:tokenStr forKey:@"deviceToken"];
[userDefaults synchronize];
}
- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
[MSTLog printdebug:@"Failed to get token, error: %@", error];
}
我使用的是 xcode 6.1。
【问题讨论】:
标签: objective-c ios8 xcode6 apple-push-notifications