3

由于 Apple 已经关闭了他们的开发者门户等待安全升级,他们创建了一个状态页面,以便我们可以监控他们重新上线的功能。我编写了一个简单的程序来监视此状态页面的更改。

我的 Mac 设置为接收发送到我的 iPhone 的 iMessage。我想知道是否有人知道当 Apple 的状态页面发生变化时,是否有可能让我编写的程序向我的 iPhone 发送 iMessage。

我通常为 iPhone 开发,所以我很欣赏人们能提供的任何见解。我在下面编写的简单程序每十五分钟检查一次是否有更新,如果有更新,则会在 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 &amp; Profiles";
}

@end
4

1 回答 1

2

我曾经尝试过这样做,但从未提出过 Objective-C 解决方案。但是,您可以让您的应用程序运行 AppleScript。这是您从命令行执行此操作的方法:

osascript -e 'tell application "Messages" to send "Test Message" to buddy "MyBuddy"'

这里的答案描述了如何从Objective C运行AppleScript:

从 Cocoa 应用程序运行 AppleScript

于 2014-06-23T17:46:52.450 回答