How can i implement apple Push Notification ?? [cl

2019-02-03 21:09发布

问题:

i am new in iphone development,i want to implement push Notification in my application. i have no idea about that. anyone give sample code.

回答1:

Firstly, you have to either rent or own a server that is responsible for communicating with Apple's APNS servers. Yes, when pushing notifications to your app's users, your server has to first push it to Apple and have Apple transfer those notifications to specific users on your behalf.

And second, override and implement the following methods in your AppDelegate's .m file:

    - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {  
    - (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error {  
    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    //You probably already implemented this one
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 

And test your code and your server with Apple's Sandbox server before you put your app into production.



回答2:

Follow Apple's Documentation.