App挂起、复原与终止[水帖]

本文详细介绍了iOS应用挂起的相关方法与通知机制,并提供了深入理解iOS应用挂起过程的资源链接。

iOS的无缝挂起体验不错,虽说这种类似“休眠”的功能在操作系统上早已出现,当App挂起要求速度更快。

讲解挂起的文章不多,大部分都是说明几个API。


挂起相关方法(NSApplication delegate)

– applicationWillFinishLaunching:
– applicationDidFinishLaunching:
– applicationShouldTerminate:
– applicationShouldTerminateAfterLastWindowClosed:
– applicationWillTerminate:
– applicationWillBecomeActive:
– applicationDidBecomeActive:
– applicationWillResignActive:
– applicationDidResignActive:
– application:didDecodeRestorableState:
– application:willEncodeRestorableState:

挂起相关通知

NSApplicationDidBecomeActiveNotification
NSApplicationDidFinishLaunchingNotification
NSApplicationWillBecomeActiveNotification
NSApplicationWillFinishLaunchingNotification
NSApplicationWillResignActiveNotification
NSApplicationWillTerminateNotification
NSApplicationDidFinishRestoringWindowsNotification

直接查文档就好了。网上有一篇文章不错  http://www.cocoanetics.com/2010/07/understanding-ios-4-backgrounding-and-delegate-messaging/ ,而且有人已经翻译了  http://gpra.pkstudio.org/archives/163 ,推荐细读。

import os from tkinter import * from tkinter.messagebox import * import psutil root = Tk() root.geometry('280x320') root.title('再见极域') root.wm_attributes('-topmost', 1) root.resizable(False, False) root.configure(bg = '#1E1E1E') font1 = ('微软雅黑', 9) font2 = ('Courier New', 16, 'bold') font3 = ('微软雅黑', 10) ICED = False TOP = True CON = True Label(root, text = '极域状态', bg = '#1E1E1E', fg = '#A0A0A0', font = font1).place(x = 0, y = 10, width = 140, height = 20) Label(root, text = '广播状态', bg = '#1E1E1E', fg = '#A0A0A0', font = font1).place(x = 140, y = 10, width = 140, height = 20) Label(root, text = '键盘状态', bg = '#1E1E1E', fg = '#A0A0A0', font = font1).place(x = 0, y = 70, width = 140, height = 20) Label(root, text = '置顶状态', bg = '#1E1E1E', fg = '#A0A0A0', font = font1).place(x = 140, y = 70, width = 140, height = 20) la = Label(root, bg = '#1E1E1E', font = ('Courier New', 13, 'bold')) lb = Label(root, bg = '#1E1E1E', font = font2) lc = Label(root, text = 'OPENED', fg = 'lime', bg = '#1E1E1E', font = font2) ld = Label(root, text = 'ON', fg = 'lime', bg = '#1E1E1E', font = font2) la.place(x = 0, y = 30, width = 140, height = 45) lb.place(x = 140, y = 30, width = 140, height = 45) lc.place(x = 0, y = 90, width = 140, height = 45) ld.place(x = 140, y = 90, width = 140, height = 45) def cba1(): ba.config(fg = '#660000', bg = 'red', activeforeground = 'red', activebackground = '#660000', text = '上键盘锁', command = cba2) lc.config(text = 'OPENED', fg = 'lime') #--------------------------- #----------开键盘锁---------- #--------------------------- def cba2(): ba.config(fg = '#006600', bg = 'lime', activeforeground = 'lime', activebackground = '#006600', text = '开键盘锁', command = cba1) lc.config(text = 'LOCKED', fg = 'red') #--------------------------- #----------上键盘锁---------- #--------------------------- ba = Button(root, text = '上键盘锁', borderwidth = 0, bg = 'red', font = font3, activeforeground = 'red', activebackground = '#660000', relief = GROOVE, fg = '#660000', command = cba2) ba.place(x = 10, y = 140, width = 125, height = 45) def cbb1(): bb.config(fg = '#660000', bg = 'red', activeforeground = 'red', activebackground = '#660000', text = '取消置顶', command = cbb2) ld.config(text = 'ON', fg = 'lime') TOP = 1 root.wm_attributes('-topmost', 1) def cbb2(): bb.config(fg = '#006600', bg = 'lime', activeforeground = 'lime', activebackground = '#006600', text = '置顶窗口', command = cbb1) ld.config(text = 'ON', fg = 'red') TOP = 0 root.wm_attributes('-topmost', 0) bb = Button(root, text = '取消置顶', borderwidth = 0, bg = 'red', font = font3, activeforeground = 'red', activebackground = '#660000', relief = GROOVE, fg = '#660000', command = cbb2) bb.place(x = 145, y = 140, width = 125, height = 45) # 这三个功能暂时没弄 def cbc(): bc['state'] = 'disabled' bd['state'] = 'normal' be['state'] = 'normal' #--------------------------- #-----------窗口化---------- #--------------------------- def cbd(): bc['state'] = 'normal' bd['state'] = 'disabled' be['state'] = 'normal' #--------------------------- #-----------最小化---------- #--------------------------- def cbe(): bc['state'] = 'normal' bd['state'] = 'normal' be['state'] = 'disabled' #--------------------------- #----------复原窗口---------- #--------------------------- bc = Button(root, text = '窗口化', borderwidth = 0, font = font3, bg = '#00A7FF', activeforeground = '#00A7FF', activebackground = '#0000BF', relief = GROOVE, fg = '#0000BF', command = cbc) bc.place(x = 10, y = 195, width = 76, height = 45) bd = Button(root, text = '最小化', borderwidth = 0, font = font3, bg = '#00A7FF', activeforeground = '#00A7FF', activebackground = '#0000BF', relief = GROOVE, fg = '#0000BF', command = cbd) bd.place(x = 96, y = 195, width = 76, height = 45) be = Button(root, text = '复原窗口', borderwidth = 0, font = font3, bg = '#00A7FF', activeforeground = '#00A7FF', activebackground = '#0000BF', relief = GROOVE, fg = '#0000BF', command = cbe) be['state'] = 'disabled' be.place(x = 182, y = 195, width = 88, height = 45) def cbf(): os.system('taskkill /im StudentMain.exe /f') showinfo('成功', '操作成功执行!') # ntsd 需要事先放到下面这个路径 def cbg(): os.system('C:\\Windows\\Temp\\ntsd.exe -c q -pn StudentMain.exe') showinfo('成功', '操作成功执行!') def cbh1(): global ICED s = [] for proc in psutil.process_iter(): try: pinfo = proc.as_dict(attrs = ['pid', 'name']) except psutil.NoSuchProcess: pass else: s.append(pinfo) for i in s: if i['name'] == 'StudentMain.exe': p = i['pid'] break pro = psutil.Process(p) pro.suspend() ICED = True bh.config(fg = '#660000', bg = 'red', text = '解冻极域', activeforeground = 'red', activebackground = '#660000', command = cbh2) def cbh2(): global ICED s = [] for proc in psutil.process_iter(): try: pinfo = proc.as_dict(attrs = ['pid', 'name']) except psutil.NoSuchProcess: pass else: s.append(pinfo) for i in s: if i['name'] == 'StudentMain.exe': p = i['pid'] break pro = psutil.Process(p) pro.resume() ICED = False bh.config(fg = '#006600', bg = 'lime', text = '冻结极域', activeforeground = 'lime', activebackground = '#006600', command = cbh1) bf = Button(root, text = 'TASKKILL', borderwidth = 0, fg = '#006600', bg = 'lime', activeforeground = 'lime', activebackground = '#006600', relief = GROOVE, command = cbf) bf.place(x = 10, y = 255, width = 80, height = 45) bg = Button(root, text = 'NTSD', borderwidth = 0, fg = '#006600', bg = 'lime', activeforeground = 'lime', activebackground = '#006600', relief = GROOVE, command = cbg) bg.place(x = 100, y = 255, width = 80, height = 45) bh = Button(root, text = '冻结极域', borderwidth = 0, fg = '#006600', bg = 'lime', activeforeground = 'lime', activebackground = '#006600', relief = GROOVE, command = cbh1) bh.place(x = 190, y = 255, width = 80, height = 45) FUCKED = False def fla(): global ICED, FUCKED, CON s = [] k = [] for proc in psutil.process_iter(): try: pinfo = proc.as_dict(attrs = ['pid', 'name']) except psutil.NoSuchProcess: pass else: s.append(pinfo['name']) k.append(pinfo) if 'StudentMain.exe' in s: if CON: la.config(font = ('Courier New', 13, 'bold')) CON = False for i in k: if i['name'] == 'StudentMain.exe': we = i['pid'] break if ICED: la.config(text = 'ICED', fg = 'yellow') lb.config(text = 'ICED', fg = 'yellow') else: la.config(text = f'ON\npid={we}', fg = 'red') lb.config(text = 'UNKNOWN', fg = 'yellow') if FUCKED: bc['state'] = 'normal' bd['state'] = 'normal' be['state'] = 'disabled' bf['state'] = 'normal' bg['state'] = 'normal' bh['state'] = 'normal' FUCKED = False else: CON = True la.config(text = 'OFF', fg = 'lime') lb.config(text = 'OFF', fg = 'lime') bc['state'] = 'disabled' bd['state'] = 'disabled' be['state'] = 'disabled' bf['state'] = 'disabled' bg['state'] = 'disabled' bh['state'] = 'disabled' la.config(font = font2) FUCKED = True if TOP: root.attributes('-topmost', 1) root.after(700, fla) root.after(500, fla) root.mainloop()
最新发布
09-15
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值