macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

requestUserAttention:

INDEX>AppKit>NSApplication

アプリケーションをドックで跳ねさせます

Objective-C

- (NSInteger)requestUserAttention:(NSRequestUserAttentionType)requestType

Swift

func requestUserAttention(_ requestType: NSRequestUserAttentionType) -> Int

解説

アプリケーションをドックで跳ねさせます。
アプリケーションがアクティブだと機能しません(-1を返します)
cancelUserAttentionRequestでやめさせることができます。
【NSRequestUserAttentionType】
Objective-C
● NSCriticalRequest 繰り返し
● NSInformationalRequest 一回だけ

Swift
● NSRequestUserAttentionType.CriticalRequest
● NSRequestUserAttentionType.InformationalRequest

返り値

Objective-C

( NSInteger )

Swift

Int

整数値

引数

( NSRequestUserAttentionType )requestType

Swift

_ requestType: NSRequestUserAttentionType

リクエストタイプ

フレームワーク

ApplicationKit

クラス

NSApplication

使用可能

10.1

編集時のバージョン

10.10

参照

例文

Objective-C

#import "Controller.h"

@implementation Controller

NSTimer *timer=nil;

- (IBAction)pushButton:(id)sender
{
    id aSignature ;
    id invocation ;
    SEL aSelector ;
    aSelector  = @selector( timerControl );
    aSignature = [ self methodSignatureForSelector:aSelector ];
    invocation = [ NSInvocation invocationWithMethodSignature:aSignature ];
    [ invocation setTarget: self ];
    [ invocation setSelector: aSelector ];
    [ invocation invoke ];
    
//アプリケーションを隠す
[NSApp hide:nil];

//1秒後に呼び出す
timer = [NSTimer scheduledTimerWithTimeInterval:1
                        invocation:invocation
                            repeats:NO];

}
-(void) timerControl{
int i;
//繰り返し呼び出す
i = [NSApp requestUserAttention:NSCriticalRequest];
//結果表示
NSLog([NSString stringWithFormat:@"%d",i]);
}

@end

Swift

//NSApplication requestUserAttention
    @IBAction func function060(sender: AnyObject) {
        //共有アプリケーションインスタンスを取得
        let anApplication = MyApplication.sharedApplication()
        anApplication.requestUserAttention(NSRequestUserAttentionType.CriticalRequest)
        //デアクティベートして
        anApplication.hide(self) //deactivate()
        //3秒後にユーザーアテンションを
        var startTimer = NSTimer.scheduledTimerWithTimeInterval(3.0, target: self, selector: Selector("requestAttention:"), userInfo: nil, repeats: false)
        //10秒後にユーザーアテンションを
        var stopTimer = NSTimer.scheduledTimerWithTimeInterval(10.0, target: self, selector: Selector("cancelAttention:"), userInfo: nil, repeats: false)
        
    }
    //タイマーが起動した時の実行メソッド ドックで跳ねる
    func requestAttention(timer:NSTimer!) {
        //共有アプリケーションインスタンスを取得
        let anApplication = MyApplication.sharedApplication()
        //ユーザーアテンションを開始
        NSLog("start attention")
        anApplication.requestUserAttention(NSRequestUserAttentionType.CriticalRequest)
    }
    //タイマーが起動した時の実行メソッド ドックではねているのをやめる
    func cancelAttention(timer:NSTimer!) {
        //共有アプリケーションインスタンスを取得
        let anApplication = MyApplication.sharedApplication()
        //ユーザーアテンションを停止
        NSLog("stop attention")
        anApplication.cancelUserAttentionRequest(0)
    }