在头文件中
#import <WatchKit/WatchKit.h>
#import <Foundation/Foundation.h>
#import <WatchConnectivity/WatchConnectivity.h>
@interface InterfaceController : WKInterfaceController<WCSessionDelegate>
- (IBAction)lastSongButtonClick;
- (IBAction)playSongButtonClick;
- (IBAction)nextSongButtonClick;
@property (strong, nonatomic) IBOutlet WKInterfaceLabel *songTitleLabel;
@property (strong, nonatomic) IBOutlet WKInterfaceButton *playSongButton;
@end
所以我实现了 WCSessionDelegate,每次我收到关于 UI 的信息时,我都希望它更新。所以在我的 .m 文件中,我有:
- (void)session:(nonnull WCSession *)session didReceiveMessage:(nonnull NSDictionary<NSString *,id> *)message{
NSString* type = [message objectForKey:@"type"];
if([type isEqualToString:@"UIUpdateInfo"]){
NSLog(@"Watch receives UI update info");
[self handleUIUpdateInfo:[message objectForKey:@"content"]];
}
}
和
- (void)handleUIUpdateInfo:(NSDictionary*)updateInfo{
[self.songTitleLabel setText:[updateInfo objectForKey:@"nowPlayingSongTitle"]];
[self.playSongButton setBackgroundImage:[updateInfo objectForKey:@"playButtonImage"]];
}
但是,它似乎没有更新。有什么合适的更新方法吗?