2014-04-04 20 views
7

Uygulamam başarıyla bildirimlerine ilişkin kayıt yapabiliyor ama ben aynı kodu uygularsanız arasında, farklı bir ekrana AppDelegate.m uygulamaylaAppDelegate.m Dışında Push Bildirimleri İçin Kayıt Yapabilir miyim?

farklı bir alana Other.m pop-up uyarı taşımak istiyoruz

-(void)buttonTapped { 
    // Register for Push Notifications 
    UIRemoteNotificationType notifyTypes = (UIRemoteNotificationTypeAlert |      UIRemoteNotificationTypeSound | 
UIRemoteNotificationTypeBadge); 

    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:notifyTypes]; 
} 


#pragma mark - APNS Functions 
-(void)application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken { 
    NSLog(@"didRegisterForRemoteNotifications - 1"); 
} 


-(void)application:application didFailToRegisterForRemoteNotificationsWithError:error { 
    NSLog(@"didFailToRegisterForRemoteNotifications"); 
} 

Ben benim AppDelegate.m içinde didRegisterForRemoteNotificationsWithDeviceToken etkinleştirirseniz

, yöntemin AppDelegate.m örneği benim Other.m çağrılan, ancak bu çalışmak istiyorum nasıl değildir: uygulamamı o kaydeder asla.

Herhangi bir fikir veya öneriniz için teşekkür ederiz.

cevap

13

Evet, tabiki.

Eğer

[[UIApplication sharedApplication] registerForRemoteNotificationTypes: 
    (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)]; 

kullanarak ancak didRegisterForRemoteNotificationsWithDeviceToken ile istediğiniz yere kaydedebilirsiniz: Bu tetiklenir böylece deviceToken AppDelegate yalnızca kullanılabilir

+0

için kayıt işlemini başarılı veya başarısız olup olmadığını öğrenmek için bir yol var mı? – Chris

+0

Uzaktan izleme kayıt defterini başarılı bir şekilde çalıştırmak veya herhangi bir ViewController'da başarısız olmak için NSNotificationCenter'ı kullanabilirsiniz – Erhan

+0

Bu, ana kuyrukta yapılmalı mı? – sudo

0
-(void)application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken 

Bu, UIApplicationDelegate protokolün protokol yöntemidir [UIApplication sharedApplication] .delegate. Bu varsayılan olarak AppDelegate'dir.

0

Kabul edilen yanıt iOS 8.0'de kullanımdan kaldırıldı. Aşağıdaki Swift kodu, iOS 9.0:

İlgili konular