比较字符时,ischar(x)&& x =='b'相当于strcmp(x,'b')?(When comparing characters, is ischar(x) && x == 'b' equivalent to strcmp(x, 'b')?)
在MATLAB中,我经常使用它来检查变量是否包含某个单个字符:
if ischar(x) && x == 'b'
为了减少混乱,我正在考虑将其改为:
if strcmp(x, 'b')
因为如果
x
不是字符或不等于'b'
,则比较将返回false,如您所料。 这些陈述在这种情况下是等同的还是有问题?更多信息:
x == 'b'
是不够的,因为当x == 98
时返回true,但在某些情况下(如验证用户输入),98
可能是无效输入而b
是有效输入。 此外,如果x
不是标准数据类型(例如,如果它是对象),则第一个失败。 拿这个(愚蠢的)例子:x = table(); x == 'b'
这会引发错误,因为没有为表定义
eq
,但是strcmp(x, 'b')
返回0,因为看起来strcmp
也执行类型检查。 是否需要这种异常处理可能取决于具体情况。In MATLAB, I often use this to check if a variable contains a certain single character:
if ischar(x) && x == 'b'
to reduce clutter I'm thinking of changing it to this:
if strcmp(x, 'b')
because if
x
isn't a character or isn't equivalent to'b'
, the comparison returns false as you would expect. Are these statements equivalent in this case or are there gotchas?More info:
x == 'b'
isn't enough because this returns true whenx == 98
, but in certain cases (like validating user input),98
may be invalid input whileb
is valid input. Also, the first one fails ifx
isn't a standard data type (if it's an object for example). Take this (stupid) example:x = table(); x == 'b'
This throws an error because
eq
isn't defined for tables, butstrcmp(x, 'b')
returns 0 because it appears thatstrcmp
also performs a type check. Whether or not this exception handling is desirable probably depends on the circumstances though.
原文:https://stackoverflow.com/questions/20848814
最满意答案
当无法发送推送通知时,Apple会通过反馈服务发送反馈消息。 反馈服务返回带有时间戳和pushtoken的json有效负载。 这些有效负载是用户可能已卸载应用程序的提示,但并非100%确定。 实际上,如果由于临时原因(例如用户没有任何可用的数据网络,处于飞行模式或从您的应用程序禁用通知),反馈消息也会警告您。 因此,我建议您记录从反馈服务返回的所有错误,然后确定您认为最能识别卸载的规则。 例如,如果用户在一周的时间内无法接收5个不同的推送通知,那么您可能希望将其视为已卸载或至少无法访问。
When a push notification can not be delivered, Apple sends a feedback message via the Feedback Service. The Feedback Service returns json payloads with timestamp and pushtoken. These payloads are hints that the user might have uninstalled the app but it's not 100% certain. Indeed, the Feedback message will also warn you if a notification could not be delivered for temporary reasons (such as the user not having any data network available, is in Airplane mode, or disabled Notifications from your app). Therefore, I would recommend you log all of the errors that are returned from the Feedback Service and then decide on a rule that you think best identifies an uninstallation. For example, if a user is not able to receive 5 different push notifications over 1 week of time, then you might want to consider him as uninstalled or, at the very least, unreachable.
相关问答
更多-
很抱歉说,但您需要找到一些硬件来测试此功能。 推送通知在模拟器中不可用。 它们需要iTunes Connect的配置配置文件,因此需要安装在设备上。 这也意味着你可能必须被接受进入苹果iPhone开发者程序,并支付你的$ 99。 在明亮的一面,使用iPhone OS 3.0更新,您可以在任何设备上测试此功能,包括第一代iPhone。 (This answer may be outdated after 2013) Sorry to say, but you'll need to find some hard ...
-
此问题与代码问题无关,这是运行PHP脚本的服务器配置的问题。 您需要为防火墙上的Apple服务器启用端口2195 (和2196以获得反馈)的“输出”规则。 This issue isn't related to an issue with the code, it's an issue with the configuration of the server the PHP script is running on. You need to enable an 'out' rule for port 219 ...
-
如果应用程序正在运行,您可以打开从应用程序到服务器的http连接,并让服务器保持打开状态,并在需要时通过它推送数据。 这基本上是COMET的工作原理。 这只会在您的应用程序运行时起作用。 如果您需要通知发生,即使用户关闭了应用程序,Apple推送通知也是您唯一的选择。 If the app is running you can open an http connection from the app to the server and have the server hold it open, pushin ...
-
您可以在多台服务器上安装证书,据我所知,没有任何限制。 唯一的建议是尽可能长时间地打开与Apple服务器的连接,并且禁止向已卸载应用程序的设备发送通知。 为此,您必须查询Apple的反馈服务 。 You can install the certificate on multiple servers, there's no limitation as far as I know. The only recommendation is that you keep the connection with the ...
-
使用带有php服务器的钛生成iphone推送通知(Generate the iphone push notification using titanium with php server)[2022-07-21]
如果您尝试将通知发送给订阅该频道的所有用户/令牌,请在检查其余部分之前尝试更改: $c_opt[CURLOPT_POSTFIELDS] = "channel=".$channel."&payload=".$json; 在: $c_opt[CURLOPT_POSTFIELDS] = "channel=".$channel."&payload=".$json.'&to_ids="everyone"'; 您有来自notify.json方法的错误消息和(来自notify.json acs rest api ... -
请检查证书是否匹配。 对于前者 如果iphone处于调试模式,则服务器还使用开发者证书进行推送通知,如果iPhone是在发行版中构建的,则服务器使用生产证书发送推送通知。 请验证您的证书是否匹配。 同时检查iPhone设置是否为您的应用启用了通知。 Please check whether the certificates matching. For ex. If the iphone is in debug mode the server also use developer certificate fo ...
-
当无法发送推送通知时,Apple会通过反馈服务发送反馈消息。 反馈服务返回带有时间戳和pushtoken的json有效负载。 这些有效负载是用户可能已卸载应用程序的提示,但并非100%确定。 实际上,如果由于临时原因(例如用户没有任何可用的数据网络,处于飞行模式或从您的应用程序禁用通知),反馈消息也会警告您。 因此,我建议您记录从反馈服务返回的所有错误,然后确定您认为最能识别卸载的规则。 例如,如果用户在一周的时间内无法接收5个不同的推送通知,那么您可能希望将其视为已卸载或至少无法访问。 When a pu ...
-
推送通知没有在iPhone应用程序中的多个设备上提供?(push notification not delivering on multiple devices in iphone app?)[2021-12-09]
最可能的解释是第3个设备令牌无效。 如果您首先发送到此设备令牌,Apple将关闭套接字并忽略其他两个设备的消息,即使它们似乎在服务器端成功传送。 如果您正在混合开发和生产设备令牌,这将解释为什么其中一些是无效的。 如果使用生产证书打开到APNS服务器的套接字,则只有生产设备令牌对该连接有效(反之亦然)。 The most likely explanation is that the 3rd device token is invalid. If you send to this device token f ... -
这里的问题是你正在使用越狱iPhone。 根据我的经验,APNS不提供“黑客”设备,第一个症状是他们不发送回复。 您可以借用设备来验证这一点。 The problem here is that you are using Jailbroken iPhone. According to my experience APNS does not serve 'hacked' devices and the first symptom is that they do not send a reply. You ca ...
-
不,不使用2195端口就无法发送APN消息。 如果要从共享服务器发送推送通知消息,请尝试使用某些第三方工具,如http://urbanairship.com/ 。 No, Its not possible to send APN message without using 2195 port. If you want to send push notification message from shared server, try using some third party tools like http ...