iphone - change label with push notification possible?
Push notification runs this on ApplePushNotificationAppDelegate.m.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
for (id key in userInfo) {
NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]);
}
ApplePushNotificationViewController *apns = [ApplePushNotificationViewController alloc];
NSLog(@"%@ changed", [apns labelchange]);
}
It goes to ApplePushNotificationViewController.m and does this
-(NSString *)labelchange{
label2.开发者_StackOverflowtext = @"labelchanged";
return @"hi";
}
and the result in the console is this without changing the label on my iPhone
2011-08-03 18:20:56.501 ApplePushNotification[1473:707] key: acme1, value: bar
2011-08-03 18:20:56.503 ApplePushNotification[1473:707] key: acme2, value: 42
2011-08-03 18:20:56.505 ApplePushNotification[1473:707] hi changed
2011-08-03 18:21:04.347 ApplePushNotification[1473:707] key: aps, value: {
alert = "You got a new denyapps!";
badge = 5;
sound = "beep.wav";
}
How come my program runs the program but does not change the label2.text to "labelchanged"?
Need to get certificate to use the push service but here are the links for the projects, "PushMeBaby" is the server.
http://dl.dropbox.com/u/12439052/ApplePushNotification.zip http://dl.dropbox.com/u/12439052/PushMeBaby.zip
Thanks.
You aren't calling init on your view controller - only alloc.
ApplePushNotificationViewController *apns = [ApplePushNotificationViewController alloc];
So your view controller isn't initialising everything.
In your view controller code, you have the labelchange method as
-(NSString *)labelchange{
label2.text = @"labelchanged";
[self changelabel];
return @"hi";
}
And the changelabel method is
-(IBAction)changelabel{
label2.text = @"button";
}
So the label's text won't be "labelchanged"
ApplePushNotificationAppDelegate.h
#import <UIKit/UIKit.h>
@class ApplePushNotificationViewController;
@interface ApplePushNotificationAppDelegate : UIViewController {
UIWindow *window;
ApplePushNotificationViewController *viewController;
}
@property (nonatomic, assign) id <View1Delegate> delegate;
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UILabel *label;
@property (nonatomic, retain) IBOutlet ApplePushNotificationViewController *viewController;
@end
ApplePushNotificationAppDelegate.m
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
viewController.label2.text = @"changetext";
}
精彩评论