简体   繁体   English

如何通过目标C代码在ios中更改通知消息?

[英]How to change notification message in ios by objective c code?

am new to ios. 是ios新手。 If we receive a notification message as "Message: @"Welcome"" then i have to show only "Welcome" in the notification of ios device. 如果我们收到通知消息为“ Message:@“ Welcome”“,那么我必须在ios设备的通知中仅显示“ Welcome”。 Is it possible and how to do it ? 有可能吗,怎么办?

Thanks in advance for any help. 在此先感谢您的帮助。

Whatever is sent in the payload of the push notification is displayed in the banner shown to the user. 推送通知的有效负载中发送的所有内容都显示在显示给用户的横幅中。 If you want to customize this message, you'll have to change what you are sending to the APNs service. 如果要自定义此消息,则必须更改要发送到APNs服务的内容。 See the push notification programming guide for details: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction.html#//apple_ref/doc/uid/TP40008194-CH1-SW1 有关详细信息,请参见推送通知编程指南: https : //developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction.html#//apple_ref/doc/uid/TP40008194-CH1-SW1

You can do this while your app is in Foreground State using remove Some specific Characters. 您可以在应用处于前景状态时使用“删除某些特定字符”来执行此操作。 follow ( how to remove first 3 characters from nsstring? ) for reference. 参阅如何从nsstring中删除前3个字符? )以供参考。

But if you are in Background state you can not handle payload. 但是,如果您处于“ 后台”状态则无法处理有效负载。 so whatever text was send from APNs service. 因此,无论从APNs服务发送的任何文本。 it will show in iOS. 它将在iOS中显示。

Suggestion : you can send payload like below 建议:您可以像下面那样发送有效载荷

aps =     {
 alert =
     {
     body = Welcome;
     type = Message;
     };
 };

So you will know the type of payload and it will show only "Welcome". 因此,您将知道有效负载的类型,并且只会显示“欢迎”。

At iOS (client) side you can only program what action to be taken when user clicks on notification or when user gets remote notification . 在iOS(客户端),您只能设置当用户单击通知或获得远程通知时要采取的措施。 For that you have to add code in the - 为此,您必须在-中添加代码

-(void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo

But you will not have any control over the notification shown while your application is in background . 但是当您的应用程序处于后台时,您将无法控制显示的通知。 For this you have to do string operations at server side from where you are sending the push . 为此,您必须在发送推送的服务器端进行字符串操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM