Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/122.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 反应本机推送通知显示在XCode控制台中,但不显示在设备上_Ios_Xcode_React Native_Notifications - Fatal编程技术网

Ios 反应本机推送通知显示在XCode控制台中,但不显示在设备上

Ios 反应本机推送通知显示在XCode控制台中,但不显示在设备上,ios,xcode,react-native,notifications,Ios,Xcode,React Native,Notifications,我已经按照react native push notification documentation()中的指南做了一个T,但是当我在手机上加载应用程序时,我无法生成简单的通知。相反,我可以在XCode控制台中看到通知。否则就不会有错误 var PushNotification = require('react-native-push-notification'); PushNotification.configure({ // (optional) Called when Token

我已经按照react native push notification documentation()中的指南做了一个T,但是当我在手机上加载应用程序时,我无法生成简单的通知。相反,我可以在XCode控制台中看到通知。否则就不会有错误

var PushNotification = require('react-native-push-notification');

PushNotification.configure({

    // (optional) Called when Token is generated (iOS and Android)
    onRegister: function(token) {
        console.log( 'TOKEN:', token );
    },

    // (required) Called when a remote or local notification is opened or received
    onNotification: function(notification) {
        console.log( 'NOTIFICATION:', notification );

        // process the notification

        // required on iOS only (see fetchCompletionHandler docs: https://facebook.github.io/react-native/docs/pushnotificationios.html)
        notification.finish(PushNotificationIOS.FetchResult.NoData);
    },

    // ANDROID ONLY: GCM Sender ID (optional - not required for local notifications, but is need to receive remote push notifications)
    senderID: "YOUR GCM SENDER ID",

    // IOS ONLY (optional): default: all - Permissions to register.
    permissions: {
        alert: true,
        badge: true,
        sound: true
    },

    // Should the initial notification be popped automatically
    // default: true
    popInitialNotification: true,

    /**
      * (optional) default: true
      * - Specified if permissions (ios) and token (android and ios) will requested or not,
      * - if not, you must call PushNotificationsHandler.requestPermissions() later
      */
    requestPermissions: true,
});

export default class PostList extends Component<{}> 
{
    componentDidMount() {
        PushNotification.localNotification({
              /* Android Only Properties */
              id: '0', // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
              ticker: "My Notification Ticker", // (optional)
              autoCancel: true, // (optional) default: true
              largeIcon: "ic_launcher", // (optional) default: "ic_launcher"
              smallIcon: "ic_notification", // (optional) default: "ic_notification" with fallback for "ic_launcher"
              bigText: "My big text that will be shown when notification is expanded", // (optional) default: "message" prop
              subText: "This is a subText", // (optional) default: none
              color: "red", // (optional) default: system default
              vibrate: true, // (optional) default: true
              vibration: 300, // vibration length in milliseconds, ignored if vibrate=false, default: 1000
              tag: 'some_tag', // (optional) add tag to message
              group: "group", // (optional) add group to message
              ongoing: false, // (optional) set whether this is an "ongoing" notification

              /* iOS and Android properties */
              title: "My Notification Title", // (optional, for iOS this is only used in apple watch, the title will be the app name on other iOS devices)
              message: "My Notification Message", // (required)
              playSound: false, // (optional) default: true
              soundName: 'default', // (optional) Sound to play when the notification is shown. Value of 'default' plays the default sound. It can be set to a custom sound such as 'android.resource://com.xyz/raw/my_sound'. It will look for the 'my_sound' audio file in 'res/raw' directory and play it. default: 'default' (default sound is played)
              number: '10', // (optional) Valid 32 bit integer specified as string. default: none (Cannot be zero)
              repeatType: 'day', // (Android only) Repeating interval. Could be one of `week`, `day`, `hour`, `minute, `time`. If specified as time, it should be accompanied by one more parameter 'repeatTime` which should the number of milliseconds between each interval
              actions: '["Yes", "No"]',  // (Android only) See the doc for notification actions to know more
          });
    }
}
var PushNotification=require('react-native-push-notification');
PushNotification.configure({
//(可选)在生成令牌时调用(iOS和Android)
onRegister:函数(令牌){
日志('TOKEN:',TOKEN);
},
//(必需)在打开或接收远程或本地通知时调用
onNotification:函数(通知){
日志('NOTIFICATION:',NOTIFICATION);
//处理通知
//仅在iOS上需要(请参阅fetchCompletionHandler文档:https://facebook.github.io/react-native/docs/pushnotificationios.html)
notification.finish(PushNotificationIOS.FetchResult.NoData);
},
//仅限ANDROID:GCM发件人ID(可选-本地通知不需要,但需要接收远程推送通知)
senderID:“您的GCM发件人ID”,
//仅限IOS(可选):默认值:全部-注册权限。
权限:{
警报:是的,
徽章:没错,
听起来:没错
},
//初始通知是否应自动弹出
//默认值:true
popInitialNotification:true,
/**
*(可选)默认值:true
*-指定是否请求权限(ios)和令牌(android和ios),
*-如果不是,则必须稍后调用PushNotificationsHandler.requestPermissions()
*/
请求权限:true,
});
导出默认类PostList扩展组件
{
componentDidMount(){
PushNotification.localNotification({
/*仅Android属性*/
id:'0',//(可选)指定为字符串的有效唯一32位整数。默认值:自动生成的唯一id
股票代码:“我的通知股票代码”,/(可选)
自动取消:true,//(可选)默认值:true
largeIcon:“ic_启动器”/(可选)默认值:“ic_启动器”
smallIcon:“ic_通知”/(可选)默认值:“ic_通知”,带有“ic_启动器”的回退功能
bigText:“通知展开时显示的我的大文本”/(可选)默认值:“消息”属性
subText:“这是一个subText”,//(可选)默认值:无
颜色:“红色”,/(可选)默认值:系统默认值
振动:真,//(可选)默认值:真
振动:300,//振动长度(毫秒),如果振动=false则忽略,默认值:1000
标记:'some_tag',//(可选)将标记添加到消息
组:“组”,//(可选)将组添加到消息
持续:false,//(可选)设置这是否为“持续”通知
/*iOS和Android属性*/
标题:“我的通知标题”、/(可选,对于iOS,这仅用于apple watch,标题将是其他iOS设备上的应用程序名称)
消息:“我的通知消息”、/(必需)
播放声音:false,//(可选)默认值:true
soundName:“默认”,显示通知时播放的//(可选)声音。“默认”值播放默认声音。可以将其设置为自定义声音,如“android”。resource://com.xyz/raw/my_sound“。它将在'res/raw'目录中查找'my_sound'音频文件并播放它。默认值:'default'(播放默认声音)
数字:“10”,//(可选)指定为字符串的有效32位整数。默认值:无(不能为零)
repeatType:'day',//(仅限Android)重复间隔。可以是'week','day','hour','minute','time'中的一个。如果指定为time,则应随附另一个参数'repeatTime',该参数应为每个间隔之间的毫秒数
操作:“[“是”、“否”]”,//(仅限Android)有关通知操作的详细信息,请参阅文档
});
}
}

事实证明,问题是我的苹果开发者帐户必须是付费的订户帐户,才能使用通知系统。我没有意识到这一点,出于某种原因,我没有得到任何错误。更新帐户后,通知开始工作。

您检查权限了吗?设备的确切iOS版本是什么?iOS 11.2.1,当手机提示我输入权限时,我按了“允许”。