Saturday, September 28, 2013

Help: How to receive push information?

- (Void) application: (UIApplication *) application didReceiveRemoteNotification: (NSDictionary *) userInfo
{
NSString * message = @ "";
id alert = [userInfo objectForKey: @ "alert"];
if ([alert isKindOfClass: [NSString class]]) {
message = alert;
} Else if ([alert isKindOfClass: [NSDictionary class]]) {
message = [alert objectForKey: @ "body"];
}
NSLog (@ "% @", message);
}
These are my source code.
Problem Description: I am using pushMeBary to my application made a push message, this time my program was tested on the real machine, xcode debug indeed entered the delegate method, but I print out the message has been displayed as null. I thought it was not running, so the message saved to a local, again send push message received, to open a file on a real machine, the file does exist, but there is no content. Where can I find the problem, carefully described, thank you! !
NSString * documentsDirectory = [NSHomeDirectory () stringByAppendingPathComponent: @ "Documents"];
NSString * filePath = [documentsDirectory stringByAppendingPathComponent: @ "pushinfo.plist"];
NSMutableArray * array;
if ([[NSFileManager defaultManager] fileExistsAtPath: filePath]) {
array = [[NSMutableArray alloc] initWithContentsOfFile: filePath];
if (array.count == 0) {
[Array addObject: message];
}
else {
[Array insertObject: message atIndex: 0];
}
}
else {
array = [[NSMutableArray alloc] init];
[Array addObject: message];
}
[Array writeToFile: filePath atomically: YES];
Reply:
When you write this alert using pushMeBary Mody? ...
Also, you say pushMeBaby do? Give you a connection
https://github.com/stefanhafeneger/PushMeBaby

In addition, you recommend a very detailed guide, but it is in English
http://mobiforge.com/developing/story/programming-apple-push-notification-services
Reply:
quote 1 floor langyufei reply:
you wrote this alert when using pushMeBary Mody? ...
Also, you say pushMeBaby do? Give you a connection
https://github.com/stefanhafeneger/PushMeBaby

In addition, you recommend a very detailed guide, but it is in English
http://mobiforge.com/developing/story/programming-apple-pu ......


Oh, and in addition, in order to make sure you write alert, I put the payload information to write it out
{"Aps": {"alert": "This is the alert message.", "Badge": 1}}
Reply:
Hello, the problem is found, the original is not lost I aps, so if userInfo to find directly in the alert is not found, it may first have to find aps, aps contents inside.
Carefully read the payload will reveal a problem.

No comments:

Post a Comment