Ho creato 2 progetti di esempio (visualizzazione singola) per testare le notifiche push, non ho aggiunto alcun codice tranne il codice di configurazione delle notifiche come riportato di seguito:swift 2: nessun callback delega per le notifiche push in opposizione all'obiettivo-
Project1 (Swift 2):
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
UIApplication.sharedApplication().registerForRemoteNotifications()
return true
}
func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
print("didRegisterUserNotificationSettings got called")
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
let trimmedDeviceToken = deviceToken.description .stringByTrimmingCharactersInSet(NSCharacterSet(charactersInString: "<>"))
.stringByReplacingOccurrencesOfString(" ", withString: "")
print("Device Token \(trimmedDeviceToken)")
}
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
print("Failed to get token, error: \(error)")
}
Project2 (Objective-C):
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIUserNotificationSettings* notificationSettings =
[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert|UIUserNotificationTypeBadge) categories:nil];
[application registerUserNotificationSettings:notificationSettings];
[application registerForRemoteNotifications];
return YES;
}
-(void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
NSLog(@"didRegisterUserNotificationSettings got called");
}
-(void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
NSString* newToken = [deviceToken description];
newToken = [newToken stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
newToken = [newToken stringByReplacingOccurrencesOfString:@" " withString:@""];
NSLog(@"Device Token %@", newToken);
}
-(void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
NSLog(@"Failed to get token, error: %@", error);
}
il progetto obiettivo-c funziona correttamente su tutti i dispositivi testati: registra se stesso per le notifiche remote e riceve un token dispositivo nel metodo di richiamata delegato, ma il progetto rapido non è riuscito a ottenere nessuno dei callback dei delegati s.
leggere quello che ho provato prima di contrassegnare questa domanda come duplicato:
1) AppID è notifica push abilitata
2) Premere tipo di certificato è la produzione e il profilo di provisioning è la produzione di AdHoc
3) entrambi i progetti utilizzano lo stesso AppID, push certificato e profilo di provisioning
4) entrambi i progetti sono stati testati su 3 diversi iPhone (5, 6 & 6Plus) tutti con iOS 9.2, eliminati con ogni installazione e riavviati tutti più volte
5) costruito entrambi i progetti con Xcode 7.2 su 2 differiscono Macchine MAC Pro
6) tutti e 3 gli iPhone utilizzano la connessione Internet senza firewall e tutte le porte sono aperte (come indicato in this technical note), anche la connessione Internet sui 3 dispositivi è una connessione 3G anziché WIFI.
7) selezionata/deselezionata Notifiche push nelle impostazioni del progetto -> capacità per entrambi i progetti (a proposito, questo punto non ha effetto mentre lo ho testato)
8) Esegui Xcode Run (il pulsante in alto) ed Esporta pacchetto ipa per entrambi i progetti
9) provato entrambi (applicazione) & ([UIApplication sharedApplication] per l'obiettivo-c e UIApplication.sharedApplication()) per rapido con il metodo registerForRemoteNotifications
10) provato un'altra marca nuovo AppID, certificato spinta e profilo di provisioning per entrambi i progetti.
11) eliminato entrambi i progetti, e ha creato un altro 2 nuovi progetti con lo stesso codice come sopra
l'Objective-C del progetto dopo tutti questi tentativi funziona bene e riceve un gettone dispositivo attraverso il metodo didRegisterForRemoteNotificationsWithDeviceToken ma il rapido uno non funziona .
Ho generato 3 APN file di log dal dispositivo iPhone 6Plus utilizzando PersistentConnectionLogging.mobileconfig
profilo da Apple, e uploaded them here, (all'interno apsd_2016_02_24_11_36_29+0300.log
il file BundleID Objective-C del progetto è XXXXX.push.notification
e il progetto BundleID rapida è XXXXX.apnsswift
)