相关疑难解决方法(0)

registerForRemoteNotificationTypes:iOS 8.0及更高版本不支持

尝试在iOS 8.x下注册推送通知时:

application.registerForRemoteNotificationTypes(UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound)
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later.
Run Code Online (Sandbox Code Playgroud)

任何想法是什么新的做法?当我在iOS 7.x上运行这个Swift应用程序时,它确实有效.

编辑

在iOS 7.x上,当我包含我得到的条件代码时(SystemVersion条件或#if __IPHONE_OS_VERSION_MAX_ALLOWED> = 80000)

dyld: Symbol not found: _OBJC_CLASS_$_UIUserNotificationSettings
Run Code Online (Sandbox Code Playgroud)

objective-c dyld apple-push-notifications ios8

209
推荐指数
6
解决办法
10万
查看次数

didReceiveRemoteNotification无法在后台运行

我正在开发一个包含大量遗留代码的大型应用程序.目前 - 有一个实现:

- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
Run Code Online (Sandbox Code Playgroud)

问题是它仅在应用程序位于前台或用户在应用程序处于后台时点击通知时调用.我试图实现:

- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
Run Code Online (Sandbox Code Playgroud)

但该应用程序的行为相同.在任何情况下 - 当应用程序在后台时,不会调用此方法.可能是什么问题呢?

xcode push-notification apple-push-notifications ios xcode6

35
推荐指数
3
解决办法
3万
查看次数

推送通知未在iOS 10上收到,但在iOS 9及更早版本上运行

我有几个用Swift 2.2编写的应用程序,使用Xcode 7.3编译并在App Store上运行.这些应用程序使用Push Notifications,在iOS 9.3及更早版本中运行良好.

但是,在已升级到iOS 10的设备上,我的应用程序不会收到任何推送通知.仍在运行iOS 9的设备仍在接收通知.

考虑到它可能是证书或授权问题,我尝试了以下内容:将我的一个应用程序升级到Swift 2.3,添加了APS环境权利并在Xcode 8中编译它,但这没有任何区别.

在我的AppDelegate中,我仍然有现有的方法来注册推送通知,其中包括:

let notificationSettings = UIUserNotificationSettings(forTypes: [.Badge, .Sound, .Alert], categories:nil)
application.registerUserNotificationSettings(notificationSettings)
Run Code Online (Sandbox Code Playgroud)

这个注册似乎在iOS 10上也很成功,因为然后调用了应用程序didRegisterForRemoteNotificationsWithDeviceToken,所以我从APNS收到一个令牌.

问题是,当我向此设备发送推送通知时,永远不会调用应用程序didReceiveRemoteNotification.

现在,这里据说在UIApplicationDelegate方法已被弃用iOS上10,我应该实现userNotificationCenter(:didReceive:withCompletionHandler :)和userNotificationCenter(:willPresent:withCompletionHandler :)

问题是我不仅仅针对iOS 10.我仍然需要应用程序才能在iOS 8和9上运行,所以我怀疑这是实现这些方法的正确方法.

如何获取现有应用的推送通知以继续处理已升级到iOS 10的设备?我需要重写代码吗?我是否只需要更新一些证书或权利,并使用一些"新"设置在Xcode 8中重新编译?

push-notification apple-push-notifications ios swift xcode8

30
推荐指数
3
解决办法
4万
查看次数

Swift 3中Any,Hashable,AnyHashable有什么区别?

我通过大量的教程来理解上述3个术语之间的区别并找到新的术语type erased容器,现在它让我感到困惑.这引起了很多疑问.

为什么Swift会介绍AnyHashable

这3个术语有什么根本区别?

区别AnyAnyHashable

区别HashableAnyHashable

何时使用Hashable以及何时使用AnyHashable

最后但最令人困惑的是,type erased在上下文中术语的含义是什么AnyHashable

我遵循了Swift Evolution Proposal SE-0131.

ios hashable associated-types swift swift3

19
推荐指数
1
解决办法
1748
查看次数

在didReceiveRemoteNotification中播放声音,而在backgorund中,使用文本到语音功能

所以我现在正在尝试的是当应用程序在后台接收远程通知(或者可能从暂停状态唤醒)时播放消息.

应用程序从暂停模式唤醒后,声音根本无法播放.

当应用程序在前台时,在didReceiveRemoteNotification:调用方法后立即播放声音.

didReceiveRemoteNotification:当应用程序从挂起模式唤醒时调用方法时,立即播放声音的适当方法是什么?

这是一些代码(语音管理器类):

-(void)textToSpeechWithMessage:(NSString*)message andLanguageCode:(NSString*)languageCode{

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *error = nil;
DLog(@"Activating audio session");
if (![audioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker | AVAudioSessionCategoryOptionMixWithOthers error:&error]) {
    DLog(@"Unable to set audio session category: %@", error);
}
BOOL result = [audioSession setActive:YES error:&error];
if (!result) {
    DLog(@"Error activating audio session: %@", error);

}else{
    AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:message];

    [utterance setRate:0.5f];

    [utterance setVolume:0.8f];

    utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:languageCode];

    [self.synthesizer speakUtterance:utterance];
}
Run Code Online (Sandbox Code Playgroud)

}

-(void)textToSpeechWithMessage:(NSString*)message{

[self textToSpeechWithMessage:message andLanguageCode:[[NSLocale preferredLanguages] objectAtIndex:0]];

}
Run Code Online (Sandbox Code Playgroud)

后来在 …

objective-c ios avspeechsynthesizer background-mode avspeechutterance

16
推荐指数
1
解决办法
1161
查看次数

如何实现iOS 10的推送通知[目标C]?

任何人都可以帮我实现iOS 10的推送通知,因为我已经实现了以下代码,但仍然遇到问题:

#define SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

if(SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(@"10.0"))
{
    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    center.delegate = self;
    [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
        if(!error){
            [[UIApplication sharedApplication] registerForRemoteNotifications];
        }
    }];
}
else {
    // Code for old versions
}
Run Code Online (Sandbox Code Playgroud)

我收到错误提示

未知的接收器UIUserNotificationCenter

先感谢您!

objective-c push-notification ios nsusernotification appdelegate

13
推荐指数
2
解决办法
6378
查看次数

推送通知未在iOS 10中接收

我的应用程序在Appstore中.推送通知在iOS 9中运行正常,但在iOS 10中无法正常工作.我没有收到iOS 10设备的任何推送通知.我检查了服务器中的设备令牌和证书.全部正确.我还在设置应用中检查了通知属性.一切都很好.但是我没有收到任何通知.我只是关闭并打开我的应用程序的通知.我打开我的应用程序来检查设备令牌是否正在改变.它已更改并更新到我的服务器.然后我正在接收通知.现在它对我的设备工作正常.

我担心这是否会影响所有用户或仅影响我.有人找到合适的解决方案请告诉我.

提前致谢

push-notification apple-push-notifications ios ios10

9
推荐指数
2
解决办法
2万
查看次数

iOS 12推送通知无效,并且在以下版本中工作,推送通知未在iOS 12中接收

对于iOS 12推送通知不起作用,并在以下版本中工作

我的应用程序在Appstore中.推送通知在iOS 11中运行良好,但在iOS 12中无法正常工作.我没有收到iOS 12设备的任何推送通知.我检查了服务器中的设备令牌和证书.全部正确.我还在设置应用中检查了通知属性.一切都很好.但是我没有收到任何通知.

这是我用于推送通知的代码.

你能告诉我什么是问题吗?如何解决这个问题?

func registerForPushNotifications() {

    if #available(iOS 10.0, *){

        let center = UNUserNotificationCenter.current()
        center.delegate = self
        center.requestAuthorization(options:[.badge, .alert, .sound]) { (granted, error) in
            if (granted)
            {
                UIApplication.shared.registerForRemoteNotifications()
            }
            else{
                //Do stuff if unsuccessful...
                 UIApplication.shared.registerForRemoteNotifications()
            }
            // Enable or disable features based on authorization.
        }
    }
    else
    {

        let types: UIUserNotificationType = [UIUserNotificationType.badge, UIUserNotificationType.alert, UIUserNotificationType.sound]
        let settings: UIUserNotificationSettings = UIUserNotificationSettings( types: types, categories: nil )
        UIApplication.shared.registerUserNotificationSettings( settings )
        UIApplication.shared.registerForRemoteNotifications()

    }

}



@available(iOS 10.0, *)
func …
Run Code Online (Sandbox Code Playgroud)

apple-push-notifications ios swift ios12

9
推荐指数
1
解决办法
3500
查看次数

推送通知在iOS 10上无效

在安装iOS 10的新更新后,推送通知无法正常工作,而相同的代码实现适用于iOS 9. iOS 10的推送通知是否有任何新功能.因为,我无法弄明白.此外,是否有必要在功能下打开推送通知.

objective-c push-notification ios swift ios10

6
推荐指数
1
解决办法
2万
查看次数