美文网首页
iOS推送注册相关知识点

iOS推送注册相关知识点

作者: 某个胖子 | 来源:发表于2015-09-24 13:22 被阅读207次

兼容iOS7 iOS8的注册方式

- (void)registRemoteNotification
{
if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0)
{
    //iOS8 以后注册方式
    [[UIApplication sharedApplication] registerForRemoteNotifications];
    UIUserNotificationSettings *setting = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert categories:nil];
    [[UIApplication sharedApplication] registerUserNotificationSettings:setting];
}
else
{
    //iOS8以前注册方式
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge)];
}
}

判断用户是否注册推送

     + (BOOL)isResigterNotification {
         if (iOS8以上) {
                UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
                if (UIUserNotificationTypeNone != setting.types) {
                   return YES;
                 }
            } else {
                UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
                if(UIRemoteNotificationTypeNone != type){
                     return YES;
                 } 
           return NO;
        }

option 相关

UIUserNotificationTypeNone  = 0 ,          == 0000                                 0
UIUserNotificationTypeBadge = 1 << 0 ,     == 0001      1左移0位     2^0 = 1
UIUserNotificationTypeSound = 1 << 1 ,     == 0010      1左移1位     2^1 = 2 
UIUserNotificationTypeAlert = 1 << 2 ,     == 0100      1左移2位     2^2 = 4

假如用户勾选推送时显示badge和提示sound,那么types的值就是 == 0001 | 0010 = 0011 == 2^0 + 2 ^1 = 3

消息提示

  • 对于简单的、无混音音频,AVAudio ToolBox框架提供了一个简单的C语言风格的音频服务

    • 使用AudioservicesPlaySystemSound函数来播放简单的声音。要遵守以下几个规则:
      1.音频长度小于30秒
      2.格式只能是PCM或者IMA4
      3.文件必须被存储为.caf、.aif、或者.wav格式
      4.简单音频不能从内存播放,而只能是磁盘文件
      除了音频限制外,对播放也没有控制权。音量位当前设备的音量。使用此函数无法循环播放,无法控制音效。但是可以设置播放结束回调函数,在音频播放结束后,做一些操作。
  • 震动
    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

  • 系统提示音
    AudioServicesPlaySystemSound(1007);

  • 自定义提示音
    /音效文件路径
    NSString *path = [[NSBundle mainBundle] pathForResource:@"message" ofType:@"wav"];
    //组装并播放音效
    SystemSoundID soundID;
    NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
    AudioServicesCreateSystemSoundID((__bridge CFURLRef)filePath, &soundID);
    //添加音频结束时的回调 (SoundFinished回调函数)
    AudioServicesAddSystemSoundCompletion(soundID, NULL, NULL, SoundFinished,sample);
    AudioServicesPlaySystemSound(soundID);
    //声音停止
    AudioServicesDisposeSystemSoundID(soundID);

  • 播放结束回调函数
    static void SoundFinished(SystemSoundID soundID,void* sample){
    /*播放全部结束,因此释放所有资源 */
    AudioServicesDisposeSystemSoundID(sample);
    CFRelease(sample);
    CFRunLoopStop(CFRunLoopGetCurrent());
    }

相关文章

  • iOS推送注册相关知识点

    兼容iOS7 iOS8的注册方式 判断用户是否注册推送 option 相关 假如用户勾选推送时显示badge和提示...

  • iOS 推送适配

    推送注册 iOS 8 以下推送注册UIRemoteNotificationType types = (UIRemo...

  • 极光推送的集成规则

    首先,iOS集成极光推送还是挺简单的。第一点,在APPdelegate中注册相关的极光推送信息,包括AppKey及...

  • ios 设置多个本地推送时间

    iOS的本地推送 1、先注册推送(注iOS8.0之前和iOS8.0之后注册的方法不一样)在AppDelegate....

  • iOS推送通知

    学习iOS开发已经两年多了,推送方面一直使用第三方极光推送,对推送没有进行系统的学习。今天我就把推送相关的知识点梳...

  • iOS 通知配置,应用前后台回调方法

    抽空整理了一下推送相关,iOS推送的原理网上一大摞,在这就不再赘述了,这里整理了一下包括注册、注册成功与否的回调,...

  • iOS 远程推送

    iOS远程推送主要流程为:注册推送的token,把token上传到服务器->接收到服务器的推送->处理推送。注册t...

  • iOS 推送总结

    注册推送 收到推送 iOS10以前 iOS10之后 关于推送的声音播放 苹果默认的推送声音就不说了,需要播放自定义...

  • iOS推送相关

    1、清除推送的badgeNumber 在bugtags后台bug时发现,有用户因为下面的代码,而崩溃。 查找原因得...

  • iOS推送相关

    最近遇到需求: App未启动状态下,接收到推送,需要跳转到具体页面. 初始想法:在启动的时候,根据启动的原因.获取...

网友评论

      本文标题:iOS推送注册相关知识点

      本文链接:https://www.haomeiwen.com/subject/djoicttx.html