开发播放器的时候,经常需要检测app进入后台(暂停播放)或者进入前台(开始播放)。方法非常简单。

1.检测app进入后台

// 在AppDelete实现该方法
- (void)applicationDidEnterBackground:(UIApplication *)application
{
//进入后台
}

2.检测app进入前台

// 在AppDelete实现该方法
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// app启动或者app从后台进入前台都会调用这个方法
} - (void)applicationWillEnterForeground:(UIApplication *)application {
// app从后台进入前台都会调用这个方法
}

3.利用通知在控制器里监听app进入前台或者后台

    // app启动或者app从后台进入前台都会调用这个方法
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
// app从后台进入前台都会调用这个方法
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationBecomeActive) name:UIApplicationWillEnterForegroundNotification object:nil];
// 添加检测app进入后台的观察者
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationEnterBackground) name: UIApplicationDidEnterBackgroundNotification object:nil];

iOS----------检测app进入后台或前台的更多相关文章

  1. iOS如何检测app从后台调回前台

    当按Home键,将应用放在后台之后,然后再次调用回来的时候,回出发AppDelegate里面的一个方法,-(void)applicationWillEnterForeground. 当应用再次回到后台 ...

  2. iOS保持App真后台运行

    https://www.jianshu.com/p/d466f2da0d33 在我看来,苹果系统与安卓系统最直观的区别就是后台处理方式了吧,安卓手机一旦开启了很多app放到后台,即使前台什么也不做,就 ...

  3. iOS蓝牙APP常驻后台

    iOS蓝牙类APP常驻后台的实现方法,经过在苹果开发者论坛询问,以及查看苹果开发者文档,最后得出正确的方法为: 1.设置plist,蓝牙权限 2.到target-capabilities-backgr ...

  4. 【转】如何使App从后台返回前台时,显示指定界面

    用户操作App至任意界面,然后按home键切到后台,然后再从后台返回前台后,如何将App显示到指定界面? 对于这个需求,具体来说分2种情况: 指定界面是一种盖在整个App上的效果.例如: 有道云笔记的 ...

  5. iOS App 获取从后台返回前台时的页面

    产品美美的给小伙伴提了一个需求,当程序从后台进入前台时,如果是指定的页面,则弹出提示框. 大家首先想到的方法就是通过 AppDelegate.h 进行控制,相对复杂的步骤就是 在程序进入后台时对当前页 ...

  6. android 监听app进入后台以及从后台进入前台

    package com.pinshang.base; import com.pinshang.common.CommonValue; import com.pinshang.investapp.Ent ...

  7. Android 监听APP进入后台或切换到前台方案对比

    在我们开发的过程中,经常会遇到需要我们判断app进入后台,或者切换到前台的情况.比如我们想判断app切换到前台时,显示一个解锁界面,要求用户输入解锁密码才能继续进行操作:我们想判断app切换到后台,记 ...

  8. 支付宝APP支付IOS手机端java后台版

    版权声明:http://blog.csdn.net/u012131769/article/details/76639527#t8 转载:http://blog.csdn.net/u012131769/ ...

  9. iOS 应用中有页面加载gif动画,从后台进入前台时就消失了

    解决办法: 在Appdelegate.m 里面有一个从后台进入前台所响应的方法,可以在该方法里post 一个通知,在加载动画里的页面接受通知,响应一定的方法即可 #pragma -mark 当程序进入 ...

随机推荐

  1. JS实现数组去重方法大总结

    js数组根据对象中的元素去重: var arr2 = [ { name: "name1", num: "1" }, { name: "name2&qu ...

  2. [Swift]LeetCode308. 二维区域和检索 - 可变 $ Range Sum Query 2D - Mutable

    Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper lef ...

  3. [Swift]LeetCode966.元音拼写检查器 | Vowel Spellchecker

    Given a wordlist, we want to implement a spellchecker that converts a query word into a correct word ...

  4. 使用SCP命令在多个linux系统间进行copy拷贝,上传,下载...

    一,什么是scp scp是linux系统下基于ssh登陆进行安全的远程文件拷贝命令.scp命令可以在linux服务器之间复制文件和目录.scp使用ssh安全协议传输数据,具有和ssh一样的验证机制,从 ...

  5. Spring中的IOC_源码_随笔

    Spring ioc 叫控制反转,也就是把创建Bean的动作交给Spring去完成. spring ioc  流程大致为 定位-> 加载->注册 先说几个比较有意思的点 1.Spring中 ...

  6. Java IO流读取文件

    使用指定编码读取文件 public static String toString(File file, String charset){ StringBuilder result = new Stri ...

  7. Python内置函数(36)——iter

    英文文档: iter(object[, sentinel]) Return an iterator object. The first argument is interpreted very dif ...

  8. Carousel轮播图

     <div id="carousel-example-generic" class="carousel slide" data-ride="ca ...

  9. Entitiy Framework Core中使用ChangeTracker持久化实体修改历史

    背景介绍 在我们的日常开发中,有时候需要记录数据库表中值的变化, 这时候我们通常会使用触发器或者使用关系型数据库中临时表(Temporal Table)或数据变更捕获(Change Data Capt ...

  10. C#版(击败100.00%的提交) - Leetcode 372. 超级次方 - 题解

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. Leetcod ...