Я пытаюсь использовать EasyAPNS в проекте для iOS 8. Но поскольку проект старый и обновлений для него нет, у меня проблемы.
Более конкретно, относительно сервера, хотя он правильно настроен как учебное видео Caixeta Raphael, представляет следующую проблему в файле журнала:
[10-Nov-2014 20:18:03 America / Sao_Paulo] Неустранимая ошибка PHP: Push Badge
должен быть либо включен, либо отключен.1) APNS :: __ construct -> File: apns.php (строка 55) 2)
APNS :: _ registerDevice -> Файл: class_APNS.php (строка 252) 3)
APNS :: _ triggerError -> Файл: class_APNS.php (строка 319)в /home/pensesof/public_html/apns/classes/class_APNS.php в строке 706
Кто-то использует или использует EasyAPNS в текущих проектах?
Я реализовал AppDelegate.m для использования в iOS8.
Сначала вы должны добавить фреймворк: AudioToolbox.framework
Перейдите в Targets> General … прокрутите вниз в Linked Frameworkworks and Libraries и нажмите на кнопку плюс, и найдите AudioToolbox.framework
После копирования и вставки этого кода для вашего AppDelgate.m:
#import "AppDelegate.h"#import <AudioToolBox/AudioToolbox.h>
@interface AppDelegate ()
@end
@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.//register to receive notifications
// Add registration for remote notifications
//[[UIApplication sharedApplication]
// registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
// For iOS 8:
UIUserNotificationSettings *settings =
[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound
categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
// Clear application badge when app launches
UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
application.applicationIconBadgeNumber = 0;return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}#pragma mark - Configuração APNS
/*
2
* ------------------------------------------------------------------------------------------
3
* BEGIN APNS CODE
4
* ------------------------------------------------------------------------------------------
5
*//**
8
* Fetch and Format Device Token and Register Important Information to Remote Server
9
*/
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {#if !TARGET_IPHONE_SIMULATOR// Get Bundle Info for Remote Registration (handy if you have more than one app)
// NSString *appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];
NSString *appName = @"TesteAPNS1";
NSString *appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];// Check what Notifications the user has turned on. We registered for all three, but they may have manually disabled some or all of them.
// NSUInteger rntypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];UIRemoteNotificationType rntypes = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications];
// Set the defaults to disabled unless we find otherwise...
NSString *pushBadge = @"disabled";
NSString *pushAlert = @"disabled";
NSString *pushSound = @"disabled";// Check what Registered Types are turned on. This is a bit tricky since if two are enabled, and one is off, it will return a number 2... not telling you which
// one is actually disabled. So we are literally checking to see if rnTypes matches what is turned on, instead of by number. The "tricky" part is that the
// single notification types will only match if they are the ONLY one enabled. Likewise, when we are checking for a pair of notifications, it will only be
// true if those two notifications are on. This is why the code is written this way
if(rntypes == UIRemoteNotificationTypeBadge){
pushBadge = @"enabled";
}
else if(rntypes == UIRemoteNotificationTypeAlert){
pushAlert = @"enabled";
}
else if(rntypes == UIRemoteNotificationTypeSound){
pushSound = @"enabled";
}
else if(rntypes == ( UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert)){
pushBadge = @"enabled";
pushAlert = @"enabled";
}
else if(rntypes == ( UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)){
pushBadge = @"enabled";
pushSound = @"enabled";
}
else if(rntypes == ( UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)){
pushAlert = @"enabled";
pushSound = @"enabled";
}
else if(rntypes == ( UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)){
pushBadge = @"enabled";
pushAlert = @"enabled";
pushSound = @"enabled";
}// Get the users Device Model, Display Name, Unique ID, Token & Version Number
UIDevice *dev = [UIDevice currentDevice];
//NSString *deviceUuid = dev.uniqueIdentifier;
NSString *deviceUuid = [[[UIDevice currentDevice] identifierForVendor ]UUIDString];// Substitui o codigo acima
NSString *deviceName = dev.name;
NSString *deviceModel = dev.model;
NSString *deviceSystemVersion = dev.systemVersion;// Prepare the Device Token for Registration (remove spaces and < >)
NSString *deviceToken = [[[[devToken description]
stringByReplacingOccurrencesOfString:@"<"withString:@""]
stringByReplacingOccurrencesOfString:@">" withString:@""]
stringByReplacingOccurrencesOfString: @" " withString: @""];// Build URL String for Registration
// !!! CHANGE "www.mywebsite.com" TO YOUR WEBSITE. Leave out the http://
// !!! SAMPLE: "secure.awesomeapp.com"
#pragma mark - Setup Your URL here!
NSString *host = @"www.mywebsite.com";#pragma mark - CHANGE "/apns.php?" TO THE PATH TO WHERE apns.php IS INSTALLED
// !!! ( MUST START WITH / AND END WITH ? ).
// !!! SAMPLE: "/path/to/apns.php?"
NSString *urlString = [@"/path/to/apns.php?"stringByAppendingString:@"task=register"];
#pragma mark - Start add propertys to url
urlString = [urlString stringByAppendingString:@"&appname="];
urlString = [urlString stringByAppendingString:appName];
urlString = [urlString stringByAppendingString:@"&appversion="];
urlString = [urlString stringByAppendingString:appVersion];
urlString = [urlString stringByAppendingString:@"&deviceuid="];
urlString = [urlString stringByAppendingString:deviceUuid];
urlString = [urlString stringByAppendingString:@"&devicetoken="];
urlString = [urlString stringByAppendingString:deviceToken];
urlString = [urlString stringByAppendingString:@"&devicename="];
urlString = [urlString stringByAppendingString:deviceName];
urlString = [urlString stringByAppendingString:@"&devicemodel="];
urlString = [urlString stringByAppendingString:deviceModel];
urlString = [urlString stringByAppendingString:@"&deviceversion="];
urlString = [urlString stringByAppendingString:deviceSystemVersion];
urlString = [urlString stringByAppendingString:@"&pushbadge="];
urlString = [urlString stringByAppendingString:pushBadge];
urlString = [urlString stringByAppendingString:@"&pushalert="];
urlString = [urlString stringByAppendingString:pushAlert];
urlString = [urlString stringByAppendingString:@"&pushsound="];
urlString = [urlString stringByAppendingString:pushSound];#pragma mark - Register the device data in server.Fire URL with data device
// Register the Device Data
// !!! CHANGE "http" TO "https" IF YOU ARE USING HTTPS PROTOCOL
NSURL *url = [[NSURL alloc] initWithScheme:@"http" host:host path:urlString];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSLog(@"Register URL: %@", url);
NSLog(@"Return Data: %@", returnData);#endif
}/**
113
* Failed to Register for Remote Notifications
114
*/
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {#if !TARGET_IPHONE_SIMULATORNSLog(@"Error in registration. Error: %@", error);#endif
}/**
125
* Remote Notification Received while application was open.
126
*/
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {#if !TARGET_IPHONE_SIMULATORNSLog(@"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);
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);NSString *badge = [apsInfo objectForKey:@"badge"];
NSLog(@"Received Push Badge: %@", badge);
application.applicationIconBadgeNumber = [[apsInfo objectForKey:@"badge"] integerValue];#endif
}
@end
//Check Notifications user has turned on.
//Registered all three, but they may have manually disabled some or all of them.
NSUInteger rntypes;
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0"))
{
//returns UIRemoteNotificationType typedef for nsuinteger
UIUserNotificationSettings * notificationSettings;
notificationSettings = [[UIApplication sharedApplication] currentUserNotificationSettings];
rntypes = [notificationSettings types];
}
else
{
rntypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
}// Set the defaults to disabled unless we find otherwise...
NSString * pushBadge = (rntypes & UIRemoteNotificationTypeBadge) ? @"enabled" : @"disabled";
NSString * pushAlert = (rntypes & UIRemoteNotificationTypeAlert) ? @"enabled" : @"disabled";
NSString * pushSound = (rntypes & UIRemoteNotificationTypeSound) ? @"enabled" : @"disabled";