由于苹果已经关闭了他们的开发者门户,等待安全升级,他们已经创建了一个状态页面,这样我们就可以监控他们重新在线带来了哪些功能。我已经写了一个简单的程序来监控这个状态页面的变化。
我的Mac设置为接收发送到我的iPhone的iMessages。我想知道,当苹果的状态页面发生变化时,是否有可能让我编写的程序向我的iPhone发送一个iMessage。
我通常是为iPhone开发的,所以我很感谢人们能提供的任何见解。我在下面编写的简单程序每15分钟检查一次是否有更新,如果有更新,则在Safari上打开更新页面。
#import "AppDelegate.h"
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
NSDateFormatter *format = [NSDateFormatter new];
[format setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:8*3600]];
[format setDateFormat:@"YYYY-MM-DD HH:mm:ss"];
NSString *text = @"";
bool no_connection;
do {
text = [[NSString alloc]initWithContentsOfURL:[NSURL URLWithString:@"https://developer.apple.com/support/system-status/"] encoding:NSASCIIStringEncoding error:NULL]; // pulls the source html from Apple's update page
NSString *status = @"No change";
if ([text rangeOfString:[self currentStatus]].location == NSNotFound) { // if cannot find the old text, then there has been a change
status = @"Update!";
}
no_connection = text == nil || [text length] == 0; // if no text or nil text then connection issue
if (no_connection) {
status = @"error making connection";
}
NSLog(@"status: %@",status); // report on status
if (no_connection) { // if no connection then try again in a minute
sleep(60);
continue;
}
sleep(900); // wait 15 minutes (60 x 15 = 900) and check again
} while ([text rangeOfString:[self currentStatus]].location != NSNotFound); // continue checking until there has been a change
NSURL *url = [NSURL URLWithString:@"https://developer.apple.com/support/system-status/"]; // bring up the update page in the browser
if( ![[NSWorkspace sharedWorkspace] openURL:url] )
NSLog(@"Failed to open url: %@",[url description]);
}
-(NSString*)currentStatus { /* returns the specific text in the html source that I'm checking for a change
"<span>" will be replaced with a hyperlink tag */
return @"<span>Certificates, Identifiers & Profiles";
}
@end发布于 2014-06-24 01:46:52
我曾经尝试过这样做,但从来没有想出一个Objective-C解决方案。但是,您可以让您的应用程序运行AppleScript。下面是从命令行执行此操作的方法:
osascript -e 'tell application "Messages" to send "Test Message" to buddy "MyBuddy"'这里的答案描述了如何从Objective C运行AppleScript:
https://stackoverflow.com/questions/17847298
复制相似问题