我刚接触iOS开发,正在尝试使用xcode6为iOS 8实现一个简单的推送通知应用程序。我已经从苹果开发人员网站获得了所有必需的证书,以及与我的应用程序id绑定的配置文件。以下是我在应用程序delegate.m中实现的代码(代码是从web借用的)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
//-- Set Notification
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)];
}
//--- your custom code
NSLog(@"Registering for push notifications...");
return YES;
}
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
NSLog(@"Registering for push notifications...II"); //to see if this code gets executed...it doesnt, why?
NSLog(@"My token is: %@", deviceToken);
}
- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
NSLog(@"Failed to get token, error: %@", error);
}我在物理iPhone上运行它,问题是我似乎无法在nslog中获取设备令牌。我甚至尝试将一个简单的nslog测试放在设备令牌代码下,但它似乎从来没有走得那么远。如果有人能指出问题是什么,那将是非常有帮助的。
谢谢。
发布于 2014-10-14 22:04:35
哥汉古特金,科尼利厄斯,
谢谢你的回复,我觉得输入我的问题的解决方案真的很愚蠢,只是因为我的iPhone没有连接到互联网,出于某种原因,我只是假设有一个通过我的笔记本电脑的系留连接,因为usb连接。
感谢你们两位抽出时间。哈姆伍德
https://stackoverflow.com/questions/26361337
复制相似问题