c_cpp 苹果のステータスバー用NowPlayingアプリ。シンプルです.TWの内容を编集する机能くらいはつけた方がいいかも.iTunes.hは脚本大桥のヘッダファイルで通常の可可用フレームワークの
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 苹果のステータスバー用NowPlayingアプリ。シンプルです.TWの内容を编集する机能くらいはつけた方がいいかも.iTunes.hは脚本大桥のヘッダファイルで通常の可可用フレームワークの相关的知识,希望对你有一定的参考价值。
#import "AppController.h"
#import "iTunes.h"
#import <Accounts/Accounts.h>
#import <Social/Social.h>
@implementation AppController
@synthesize accountStore;
- (void)awakeFromNib{
statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
[statusItem setTitle:@""];
[statusItem setHighlightMode:YES];
[statusItem setImage:[NSImage imageNamed:@"icon_mucast"]];
[statusItem setMenu:statusMenu];
iTunesApp = [SBApplication applicationWithBundleIdentifier:@"com.apple.itunes"];
m = 0;
accountStore = [[ACAccountStore alloc] init];
accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
accountArray = [accountStore accountsWithAccountType:accountType];
[accountStore
requestAccessToAccountsWithType:accountType
options:nil
completion:^(BOOL granted, NSError *error) {
if (granted) {
menuAcc = [[NSMenu alloc]init];
int i;
for (i=0; i < [accountArray count]; i++) {
if (i == 0) {
menuItems = [menuAcc insertItemWithTitle:[[accountArray objectAtIndex:i] username]
action:@selector(press:)
keyEquivalent:@"" atIndex:i];
[menuItems setTarget:self];
[menuItems setState:NSOnState];
[menuItems setRepresentedObject:accountArray];
}
else{
menuItems = [menuAcc insertItemWithTitle:[[accountArray objectAtIndex:i] username] action:@selector(press:) keyEquivalent:@"" atIndex:i];
[menuItems setTarget:self];
[menuItems setState:NSOffState];
[menuItems setRepresentedObject:accountArray];
}
}
//NSMenuItemのsetSubmenuメソッドの引数がNSMenu
[_subMenu setSubmenu:menuAcc];
[menuAcc setAutoenablesItems:NO];
[_subMenu setEnabled:YES];
}
}];
if([iTunesApp isRunning])
{
if (iTunesEPlSPlaying == [iTunesApp playerState])
{
[menuItem1 setTitle:@"停止する"];
}
else if(iTunesEPlSPaused == [iTunesApp playerState])
{
[menuItem1 setTitle:@"再生"];
}
}
}
- (IBAction)nowplayinglog:(id)sender {
NSString *currentTrackName = [iTunesApp.currentTrack name];
NSString *currentTrackArtist = [iTunesApp.currentTrack artist];
NSString *nowplaying = [NSString stringWithFormat:@"#nowplaying %@ - %@", currentTrackName, currentTrackArtist];
[accountStore
requestAccessToAccountsWithType:accountType
options:nil
completion:^(BOOL granted, NSError *error) {
if (granted) {
if (accountArray.count > 0) {
NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/update.json"];
NSDictionary *params = [NSDictionary dictionaryWithObject:nowplaying forKey:@"status"]
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodPOST
URL:url
parameters:params];
[request setAccount:[accountArray objectAtIndex:m]];
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSLog(@"responseData=%@: %@", [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding], [[accountArray objectAtIndex:m]username]);
}];
}
}
}];
}
- (IBAction)play:(id)sender {
[iTunesApp playpause];
if (iTunesEPlSPlaying == [iTunesApp playerState])
{
[menuItem1 setTitle:@"停止する"];
}
else if(iTunesEPlSPaused == [iTunesApp playerState])
{
[menuItem1 setTitle:@"再生"];
}
}
- (IBAction)playNext:(id)sender {
[iTunesApp nextTrack];
}
- (IBAction)playLast:(id)sender {
[iTunesApp previousTrack];
}
- (void)press:(id)sender
{
NSMenuItem *mi = (NSMenuItem*)sender;
m = [[[mi parentItem] submenu] indexOfItem:mi];
NSLog(@"%ld",(long)m);
[menuItems setState:NSOffState];
for(NSMenuItem *mis in menuAcc.itemArray){
[mis setState:NSOffState];
}
[sender setState:NSOnState];
}
@end
#import <Foundation/Foundation.h>
#import "iTunes.h"
#import <Accounts/Accounts.h>
#import <Social/Social.h>
@interface AppController : NSObject
{
IBOutlet NSMenu *statusMenu;
NSStatusItem *statusItem;
NSImage *statusImage;
iTunesApplication *iTunesApp;
NSString *twitterTimelineUsername;
NSString *twitterGetTimelineStatus;
NSArray *timelineStatuses;
ACAccountStore *accountStore;
ACAccountType *accountType;
NSArray *accountArray;
NSString *accessToken;
NSString *accessTokenSecret;
NSMenuItem *menuItem1;
NSMenuItem *menuItems;
NSMenu *menuAcc;
NSInteger m;
}
- (IBAction)nowplayinglog:(id)sender;
- (IBAction)play:(id)sender;
- (IBAction)playNext:(id)sender;
- (IBAction)playLast:(id)sender;
- (void)press:(id)sender;
@property (weak) IBOutlet NSMenu *menuAccount;
@property ACAccountStore *accountStore;
@property (weak) IBOutlet NSMenuItem *subMenu;
@end
以上是关于c_cpp 苹果のステータスバー用NowPlayingアプリ。シンプルです.TWの内容を编集する机能くらいはつけた方がいいかも.iTunes.hは脚本大桥のヘッダファイルで通常の可可用フレームワークの的主要内容,如果未能解决你的问题,请参考以下文章