1

iOS 8 용 프로젝트에서 EasyAPNS를 사용하려고합니다.하지만 프로젝트가 오래되어 업데이트가 없기 때문에 문제가 있습니다.iOS 8에 EasyAPNS를 구현하는 방법은 무엇입니까?

구체적으로는, 서버에 대하여, 그것이 정확하게 가이드 비디오 Caixeta 라파엘로 구성되어 있지만,이 로그 파일의 다음 문제 제시한다

[10-Nov-2014 20:18:03 America/Sao_Paulo] PHP Fatal error: Push Badge must be either Enabled or Disabled.

1) APNS::__construct -> File: apns.php (line 55) 2) APNS::_registerDevice -> File: class_APNS.php (line 252) 3) APNS::_triggerError -> File: class_APNS.php (line 319)

in /home/pensesof/public_html/apns/classes/class_APNS.php on line 706

사람이 사용하거나 온 전류 EasyAPNS를 사용 프로젝트?

+0

이 높은 EasyAPNS이 얼마나 낡은 주어진 사용에 좋습니다. Apple은 APNS 시스템을 지속적으로 개선했으며 php는 지속적으로 업데이트되었습니다. [PyAPNs] (https://github.com/djacobs/PyAPNs)와 같은 것을 사용 해본 적이 있습니까? 여전히 적극적으로 업데이트되고 있습니다. – brandonscript

+0

PHP는 나를 위해 더 쉽습니다 ... 그리고 이것은 직업이고 내 클라이언트의 서브는 PHP/mysql뿐입니다. Thx –

+0

고객에게 EasyAPNS의 현재 상태를 설명 할 가치가 있으며, "단지"때문에 사용할 것이라고 결정한 것이 아니라 올바른 도구를 사용해야한다고 설명합니다. – brandonscript

답변

0

iOS8에서 사용되는 AppDelegate.m을 구현했습니다.

먼저 u는 프레임 워크에 추가해야합니다 AudioToolbox.framework를

이동 대상> 일반 ... 링크 프레임 워크 및 라이브러리에서 아래로 스크롤 플러스 버튼을 클릭하고 복사 한 후 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_SIMULATOR 



    NSLog(@"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_SIMULATOR 



    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); 

    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); 



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

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

    application.applicationIconBadgeNumber = [[apsInfo objectForKey:@"badge"] integerValue]; 



#endif 

} 
@end 
+0

좋은 시작이지만 약간의 실수, isRegisteredForRemoteNotifications는 bool을 반환합니다. –

1
//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"; 
+0

도움을 주셔서 감사합니다. 그러나이 코드를 포기했습니다. 이 서비스는 매우 오래되었고 시대가 오래되었습니다. 그래서 해결하기 위해 PHP를 사용하여 자체 APNS 서버를 만들었습니다. AppDelegate에서 방금 푸시 서비스를 시작했습니다. –

관련 문제