2011-08-03 38 views
0

推送通知在ApplePushNotificationAppDelegate.m上運行。iphone - 更改標籤推送通知可能嗎?

- (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]); 
} 

它去ApplePushNotificationViewController.m和做到這一點

-(NSString *)labelchange{ 
label2.text = @"labelchanged"; 
return @"hi"; 
} 

,結果在控制檯這是在不改變標籤上我的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"; 
} 

爲什麼我的程序運行該程序,但不會將label2.text更改爲「labelchanged」?

需要獲得使用推送服務的證書,但這裏是項目的鏈接,「PushMeBaby」是服務器。

http://dl.dropbox.com/u/12439052/ApplePushNotification.zip http://dl.dropbox.com/u/12439052/PushMeBaby.zip

感謝。

+0

如果你已經初始化你LABEL2?它可能不會被初始化,爲什麼它不改變它的文本。 – Mahesh

回答

0

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"; 
} 
0

你不是在你的視圖控制器上調用init - 只有alloc。

ApplePushNotificationViewController *apns = [ApplePushNotificationViewController alloc]; 

所以你的視圖控制器不是初始化所有的東西。

在您的視圖控制器代碼,您必須促使labelChange方法

-(NSString *)labelchange{ 
    label2.text = @"labelchanged"; 
    [self changelabel]; 
    return @"hi"; 
} 

而且changelabel方法是

-(IBAction)changelabel{ 
label2.text = @"button"; 
} 

所以標籤的文本不會被 「labelchanged」

+0

即使我初始化它,它仍然不工作 –

+0

發佈您的代碼爲'ApplePushNotificationViewController.m'和'ApplePushNotificationViewController.h' –

+0

它的內部http://dl.dropbox.com/u/12439052/ApplePushNotification.zip我想知道如果它是可能的... –