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.